cell 加button
UIButton *MapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[MapButton setFrame:CGRectMake(110,180 , 75, 30)];
[MapButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[MapButton setTitle:@"地图" forState:UIControlStateNormal];
MapButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
[MapButton addTarget:self action:@selector(dinnerMapButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:MapButton ];
点击按钮响应的方法
-(void)MapButtonClick:(id)sender
{
UIButton *mapButton = (UIButton *)sender;
UITableViewCell *buttonCell = (UITableViewCell *)[mapButton superview];
NSUInteger section = [[myTableView indexPathForCell:buttonCell] section];
NSUInteger row = [[myTableView indexPathForCell:buttonCell] row];
NSLog(@" section %d",section);
}
tip:
[dinnerMapButton addTarget:self action:@selector(dinnerMapButtonClick:) forControlEvents:UIControlEventTouchUpInside];
冒号别忘记了