将 UIButton 标题设置为选定的表格单元格 [英] Set UIButton title to selected table cell

查看:71
本文介绍了将 UIButton 标题设置为选定的表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UITableView loading a different array when clicking on different buttons. What I want is to update the UIButton titles to the selected table cell. So for example: the user has selected table row 4 which has the text "April 2013". The button updates its title to "April 2013". This is working. Now, the user switches between TableView by clicking on a button (loading new data in the SAME array). The UITableView with table row 4 named "April 2013" updates its fields using the same array and the field previously selected is still preserved but now with different data. Yet the UIButton title is still showing "April 2013", I want to change it so that when clicking on the button and changing the data of the array, the button title changes aswell.

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 标题以显示当前选定的表格单元格.

In short: How do I update a UIButton title to show a current selected table cell.

我希望你能理解这个问题.

I hope you understand the question.

推荐答案

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

Instead of setting the button title based on the contents of the cell, try setting the title based on the contents of the array:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *titleToUse = [arrayWithData objectAtIndex:indexPath.row];

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

}

这篇关于将 UIButton 标题设置为选定的表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆