将UIButton标题设置为选定的表格单元格

当点击不同的按钮时,我有一个UITableView加载一个不同的数组。 我想要的是将UIButton标题更新为选定的表格单元格。 例如:用户选择了表格第4行,其中包含文本“2013年4月”。 该按钮将其标题更新为“2013年4月”。 这很有效。 现在,用户通过单击按钮(在SAMEarrays中加载新数据)在TableView之间切换。 名为“2013年4月”的表格第4行的UITableView使用相同的数组更新其字段,之前选择的字段仍然保留,但现在具有不同的数据。 然而UIButton标题仍然显示“2013年4月”,我想改变它,以便当点击按钮并更改数组的数据时,按钮标题也会改变。

didSelectRowAtIndexPath方法:

 if([self.delegate respondsToSelector:@selector(dateSpecifiedButtonText:)]) { [self.delegate dateSpecifiedButtonText:selCell.textLabel.text]; } 

ViewController.m:

 - (void)dateSpecifiedButtonText:strText2 { [self.dateSpecifiedButton setTitle:strText2 forState:UIControlStateNormal]; } 

简而言之:如何更新UIButton标题以显示当前选定的表格单元格。

我希望你理解这个问题。

而不是根据单元格的内容设置按钮标题,尝试根据数组的内容设置标题:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *titleToUse = [arrayWithData objectAtIndex:indexPath.row]; if([self.delegate respondsToSelector:@selector(dateSpecifiedButtonText:)]) { [self.delegate dateSpecifiedButtonText:titleToUse]; } }