![](/img/trans.png)
[英]UITableViewCell accessoryView overlap custom button of cell OR how to change accessoryView position?
[英]Changing a custom accessoryView in a uitableviewcell?
我試圖在用戶單擊單元格后立即更改uitableviewcell的自定義配件視圖。 我該怎么做?
作為記錄,我正在使用Matt Gallagher的自定義表格視圖教程:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
下載源鏈接: http : //projectswithlove.com/projects/EasyCustomTable.zip
編輯
嘗試了此代碼,但僅在修飾后更改了附件。 還嘗試了willSelectRowAtIndexPath具有相同的結果。
- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
return indexPath;
}
編輯
通過使單元格的背景圖像包含附件解決了問題。 因此,通過使其成為圖像的一部分來“偽造”附件
也許您可以嘗試在willSelectRowAtIndexPath / didSelectRowAtIndexPath中重新加載單元格:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:NO];
}
另一個建議:didSelectRowAtIndexPath 返回void而不是NSIndexPath。
您可以按如下所示的選擇方法更改附件視圖:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = newView;
}
這只是獲取當前選擇的單元格,然后更改其附件視圖。 您的視圖對象將放在newView所在的位置。
使用UIImageView的HighlightedImage屬性:
UIImageView* arrowView = [[UIImageView alloc] initWithImage:normalImage];
arrowView.highlightedImage = selectedImage;
cell.accessoryView = arrowView;
[arrowView release];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.