有什麼辦法可以改變當UITableView處於編輯模式時顯示的重新排序控件的圖像?我有一個我想顯示的UIImage,而不是通常的灰色條。UITableViewCell自定義重新排序控制
我必須繼承UITableViewCell才能完成此操作嗎?
有什麼辦法可以改變當UITableView處於編輯模式時顯示的重新排序控件的圖像?我有一個我想顯示的UIImage,而不是通常的灰色條。UITableViewCell自定義重新排序控制
我必須繼承UITableViewCell才能完成此操作嗎?
我最近在這方面做了一些小小的工作,但總結不全。我嘗試設置自己的editingAccesoryView,但無法讓重新排序控件更改。奇。
我的猜測是,它是與在UITableViewCell的文檔以下注釋重新:showsReorderControl:
如果該值是YES,重新排序 控制暫時替換任何 附件視圖。
換句話說,editingAccessoryView正在被重新排序控制視圖取代,這可能是我們無法重寫重新排序控件的原因。希望有人能找到解決方法。
您將單元的editingAccessoryView
屬性設置爲包含所需圖像的圖像視圖。
另外,我會提醒你在做這件事時要小心。將自定義圖形替換爲重新排序圖形等系統標準時,會造成令用戶困惑的嚴重風險。標準UI語法告訴他們在重新排序時期望標準圖形,他們可能不瞭解自定義圖形的意義。
我最近遇到了需要改變形象爲重排序控制跑了,因爲我的子類UITableViewCell
提供我自己的自定義表格單元格。作爲這項工作的一部分,我將單元格的背景更改爲默認顏色以外的其他內容。
一切工作正常,但是當我將UITableView
置於編輯模式時,重新排序控件將出現,並帶有白色背景 - 而不是我用於單元格的背景顏色。這看起來不太好,我想要背景匹配。
在各種版本的iOS過程中,UITableViewCell
中的視圖層次結構已更改。我採取了一種方法來遍歷整個視圖,直到找到UITableViewCellReorderControl
私人類。我相信這將適用於iOS 5以及此答案時的所有後續iOS版本。請注意,儘管UITableViewCellReorderControl
類本身是私有的,但我沒有使用任何私有API來找到它。
首先,這是掃描重新排序控制的代碼;我假設文本「重新排序」將在類名 - 這蘋果可能在未來改變:
-(UIView *) findReorderView:(UIView *) view
{
UIView *reorderView = nil;
for (UIView *subview in view.subviews)
{
if ([[[subview class] description] rangeOfString:@"Reorder"].location != NSNotFound)
{
reorderView = subview;
break;
}
else
{
reorderView = [self findReorderView:subview];
if (reorderView != nil)
{
break;
}
}
}
return reorderView;
}
在你自定義的UITableViewCell子類中,你將覆蓋-(void) setEditing:animated:
這裏找到重新排序控制。如果你試圖找到這種控制時該表是不是在編輯模式,重新排序控制不會在視圖層次結構的單元:
-(void) setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (editing)
{
// find the reorder view here
// place the previous method either directly in your
// subclassed UITableViewCell, or in a category
// defined on UIView
UIView *reorderView = [self findReorderView:self];
if (reorderView)
{
// here, I am changing the background color to match my custom cell
// you may not want or need to do this
reorderView.backgroundColor = self.contentView.backgroundColor;
// now scan the reorder control's subviews for the reorder image
for (UIView *sv in reorderView.subviews)
{
if ([sv isKindOfClass:[UIImageView class]])
{
// and replace the image with one that you want
((UIImageView *)sv).image = [UIImage imageNamed:@"yourImage.png"];
// it may be necessary to properly size the image's frame
// for your new image - in my experience, this was necessary
// the upper left position of the UIImageView's frame
// does not seem to matter - the parent reorder control
// will center it properly for you
sv.frame = CGRectMake(0, 0, 48.0, 48.0);
}
}
}
}
}
您的里程可能會有所不同;我希望這對你有用。
也許我們都在推翻這一點。 :)
只需將自定義UIImageView
置於默認移動附件的頂部,以便將其覆蓋。完成。
它與默認視圖沒有區別;線條是波浪形而不是筆直的... – 2010-08-23 13:18:24
我需要在哪裏做到這一點?如果我在實例化單元格時執行該操作,則唯一獲得的是默認重新排序視圖左側的附加視圖。拖動新圖像時,我也無法對單元格重新排序。我試着設置'cell.editingAccessoryType = UITableViewCellEditingStyleNone;'但無濟於事。 – 2010-08-23 13:25:14
文檔聲稱使用'UITableViewCellAccessoryDetailDisclosureButton'或編輯附件視圖從不出現或響應。閱讀UITableView文檔以獲取詳細信息。 – TechZen 2010-08-23 21:57:52