我有一个很大的问题.我正在尝试在每个UITableViewCell中创建一个最喜欢的按钮UITableView.这非常有效,我现在按下时会执行一个动作和选择器.
accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
accessory.frame = CGRectMake(0, 0, 15, 15);
accessory.userInteractionEnabled = YES;
[accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = accessory;
Run Code Online (Sandbox Code Playgroud)
和选择器:
- (void) didTapStar {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:/* indexPath? */];
accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"stared.png"] forState:UIControlStateNormal];
accessory.frame = CGRectMake(0, 0, 26, 26);
accessory.userInteractionEnabled = YES;
[accessory addTarget:self action:@selector(didTapStar) forControlEvents:UIControlEventTouchDown];
newCell.accessoryView = accessory;
}
Run Code Online (Sandbox Code Playgroud)
现在,问题在于:我想知道按下的配件属于哪一行.我怎样才能做到这一点?
谢谢 :)
如何在a上添加自定义按钮UITableViewCell,然后使用该按钮删除单元格而不使用Interface Builder和Custom Cell?