1
我正在制作一个iOS应用程序,它有一个Table View
与原型单元格。我配置了cellForRowAtIndexpath
方法中的单元格,并且工作正常,但是出现问题的地方是我想在创建按钮后更改按钮中的文本。我希望它能够在按下按钮时更改按钮文本。我试图做的:当按钮是iOS自定义单元格的子视图时,如何动态更改按钮文本?
[button setTitle:@"Change" forState:UIControlStateNormal];
运行,当我点击的按钮clickMethod内,但无论我按哪个按钮改变了最后一个单元格中的文本。我上面试过的东西不起作用,因为我有同一个按钮的多个实例(每行一个)所以有人知道我可以如何改变我点击的按钮的文本。创建按钮的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//configure cell
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(clickMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Button" forState:UIControlStateNormal]
[button setTag:6789];//set tag so we can identify the button
button.Frame=CGRectMake(218, 5, 99, 53);
[cell addSubview:button];//put the button in the cell
[cell setIndentationWidth:45];
[cell setIndentationLevel:1];
return cell;//return the cell object
非常感谢帮助。我可以发布更多的代码,但我不认为这与问题相关。 在此先感谢。
请在请求前请在Google上搜索。有许多解决方案已经可用。 – TheTiger
我看了之前,我什么都找不到,但我会再看。 – user2615467
而你的细胞似乎并不习惯......是吗? – TheTiger