最佳答案
创建从单元格到 Controller 的 Action 。现在您可以引用您的单元格按钮
-(void)followButtonActionFromTableViewCell:(UIButton *)sender
{
[self followUnfolloWithButton:sender]
}
-(void)followUnfolloWithButton:(UIButton *)sender{
//you may need to call web service and set button accordingly
[sender setTitle:@"Follow" forState:UIControlStateNormal];
[sender setBackgroundColor:[UIColor yellowColor]];//set your colour
}
如果你想重新加载 TableView ,请使用。
UIButton * button = (UIButton*)sender;
CGRect frameRect ;
NSIndexPath * indexPath ;
frameRect=[button convertRect:button.bounds toView:self.tableView];
indexPath= [self.tableView indexPathForRowAtPoint:frameRect.origin];
//Reload
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
在 cellForRowAtIndexPath 方法中保存 follow/following put 检查条件的状态。和
update your model by sender.tag
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//...your code
cell.yourFollowButton.tag=indexPath.row;
//check condition and set button text and colour
}
关于ios - 在 UITableView 中单击时更改 UIButton 颜色和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34762750/