Pal*_*dis 9 iphone objective-c uitableview ios
我正在尝试在选择其行时更改UITableViewCell的附件视图,我有以下代码:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [self tableView:aTableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activityView startAnimating];
cell.accessoryView = activityView;
[activityView release];
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有任何想法吗?
您不应该向tableview数据源(您的自己)询问单元格.因为这将创建一个刚刚不显示的新单元格.
更换
UITableViewCell* cell = [self tableView:aTableView cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
同
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
UIImage *normalImage = [UIImage imageNamed:@"cell-accessory.png"];
UIImage *selectedImage = [UIImage imageNamed:@"cell-accessory-selected.png"];
UIButton *accessoryView = [UIButton buttonWithType:UIButtonTypeCustom];
accessoryView.frame = CGRectMake(0.0f, 0.0f, normalImage.size.width, normalImage.size.height);
accessoryView.userInteractionEnabled = NO;
[accessoryView setImage:normalImage forState:UIControlStateNormal];
[accessoryView setImage:selectedImage forState:UIControlStateHighlighted];
cell.accessoryView = accessoryView;
Run Code Online (Sandbox Code Playgroud)