我想将UIButton文本更改为UITableView中选定的单元格。通常情况下会这样做。
TableView.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if([self.delegate respondsToSelector:@selector(ButtonText:)]) {
[self.delegate ButtonText:selCell.textLabel.text];
}
}ViewController.m
- (void)dateSpecifiedButtonText:strText2
{
[self.dateSpecifiedButton setTitle:strText2 forState:UIControlStateNormal];
}当我选择单元格时,这是有效的,但是当您单击另一个按钮时,我想要的是将按钮更改为单元格。因此,我需要重写此方法而不使用didSelectRowAtIndex,但我不知道如何重写。
发布于 2013-06-03 12:54:59
如果您知道其中按钮所在的单元格的indexPath
UITableViewCell *cell = [self.tableView cellForIndexPath:indexPath];如果您刚刚将按钮添加到单元格的contentView中,则向该按钮添加一个唯一的标记。
UIButton *button = (UIButton *)[cell.contentView viewForTag:55];现在有了按钮实例,将文本设置为它。
https://stackoverflow.com/questions/16897137
复制相似问题