首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UITableViewCell每行中的UIButton轻巧获得cell的IndexPath

2013-02-06 
UITableViewCell每行中的UIButton轻松获得cell的IndexPathUIButton *button [UIButton buttonWithType:U

UITableViewCell每行中的UIButton轻松获得cell的IndexPath

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];button.frame = CGRectMake(0.0, 0.0, 100, 100);// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];cell.accessoryView = button;- (void)checkButtonTapped:(id)sender event:(id)event{NSSet *touches = [event allTouches];UITouch *touch = [touches anyObject];CGPoint currentTouchPosition = [touch locationInView:self.tableView];    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];if (indexPath != nil){}}

热点排行