我有一个带有Button的截面页脚,但我不知道如何检测在我的TableView中单击了哪个部分页脚。我知道我必须使用类似“标签”的东西,但是怎么样?
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
self.footerHeartView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 60)];
[self.footerHeartView addSubview:viewFotter];
UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 300, 60)];
self.heartButton = [[UIButton alloc]initWithFrame:CGRectMake(200, 5, 70, 50)];
self.heartButton.tag = section;
self.heartButton.backgroundColor = [UIColor greenColor];
[self.heartButton addTarget:self
action:@selector(heartClick:)
forControlEvents:UIControlEventTouchUpInside];
[viewFotter addSubview:self.heartButton];
[viewFotter setBackgroundColor:[UIColor whiteColor]];
return self.footerHeartView;
}
- (void)heartClick:(UIButton*)sender {
NSLog(@"CLICK");
[[GTAppController sharedInstance].api sendLike:1 itemId:[[self.newsList objectAtIndex:???????]objectForKey:@"testId"]];
}
感谢您的时间!
答案 0 :(得分:2)
您将发件人转换为按钮并阅读标记:
- (void)heartClick:(UIButton*)sender {
NSLog(@"CLICK");
UIButton* sectionButton = (UIButton*)sender;
int section = sectionButton.tag;
[[GTAppController sharedInstance].api sendLike:1 itemId:[[self.newsList objectAtIndex:???????]objectForKey:@"testId"]];
}
希望得到这个帮助。