【发布时间】:2014-08-28 19:48:09
【问题描述】:
我想在按钮单击时更改按钮上的图像。该按钮放置在表格单元格中。图像正在成功更改。但是,当每 5 个单元格按钮图像也更改后默认滚动表格时,我没有更改它。表示表格中的新单元格,不愿意更改。此单元格可重复使用,由故事板创建。
如何将该按钮用作切换按钮。我怎样才能做到这一点。
- (NSIndexPath *)indexPathWithSubview:(UIView *)subview {
while (![subview isKindOfClass:[UITableViewCell self]] && subview) {
subview = subview.superview;
}
return [self.table indexPathForCell:(UITableViewCell *)subview];
}
- (IBAction)btnCheckedCellPressed:(id)sender{
NSIndexPath *myIP = [self indexPathWithSubview:(UIButton *)sender];
MyWantsTableViewCell* cell = (MyWantsTableViewCell *)[self.table cellForRowAtIndexPath:myIP];
if (cell.btnEdit.currentImage == [UIImage imageNamed:@"checkbox-active"]) {
[cell.btnEdit setImage:[UIImage imageNamed:@"checkbox-deactive"]
forState:UIControlStateNormal];
} else {
[cell.btnEdit setImage:[UIImage imageNamed:@"checkbox-active"]
forState:UIControlStateNormal];
}
// [self.table beginUpdates];
// [self.table reloadRowsAtIndexPaths:@[myIP] withRowAnimation:UITableViewRowAnimationFade];
// [self.table endUpdates];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MyWantsTableViewCell *cell=nil;
static NSString *AutoCompleteRowIdentifier = @"MyWantsTableViewCellEdit";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[MyWantsTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier];
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.imgProduct];
}
cell.selectionStyle = UITableViewCellAccessoryNone;
cell.btnEdit.tag = indexPath.row;
return cell;
}
【问题讨论】:
标签: ios iphone objective-c ios7 storyboard