gpt4 book ai didi

ios - 在 UITableView 中单击时更改 UIButton 颜色和文本

转载 作者:行者123 更新时间:2023-11-29 01:19:42 24 4
gpt4 key购买 nike

enter image description here

我必须在单击每个单元格时将此“关注”按钮更改为“关注”,当我再次点击“关注”时,它应该返回到“关注”。怎么可能?

最佳答案

创建从单元格到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com