2013-02-07 165 views
0

我有一个表格,其中有5个单元格。在每个单元格中都有一个按钮。我需要在某些条件下动态更改这些按钮。如何在表格视图中动态更改按钮。在表格视图单元格中动态更改按钮

+0

你使用故事板吗?,你使用静态细胞? – tkanzakic

+0

你的意思是改变什么?改变行为?改变看看?更改文字? – moonwave99

+0

@ moonwave99我需要改变行为。例如,如果它是“电话”,如果我点击它应该改为“短信”。一旦通话完成,下次我只能发短信。 – 2vision2

回答

1

你可以做的是编写一个函数,它将改变按钮的值,然后你可以调用该函数。在更改按钮值后,使用下面提到的任何一种方法:

您可以使用:[tableview reloadData];重新加载所有表数据。

OR

您可以使用下面的方法重新加载特定行:

[tableview reloadRowsAtIndexPaths: indexPath withRowAnimation:anyKindOfAnimation];

1

您可以通过-visibleCells查询所有可见单元格的表视图,让你的按钮引用(假设你有一个UITableViewCell子类的按钮属性)并更改它们。

0

首先你需要为每个按钮设置标签。这可以通过

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
//Your code 
cell.Button.tag = indexPath.row; 
[cell.Button addTarget:self action:@selector(buttonClick1:) forControlEvents:UIControlEventTouchUpInside]; 

}

可以做到,那么你可以从这个方法

- (IBAction)buttonClick1:(id)sender { 

int tagNo =[sender tag]; 
UITableViewCell *cellclicked = [self.tblProfileFollowing cellForRowAtIndexPath:[NSIndexPath indexPathForRow:tagNo inSection:0]]; 
//Now change the action for the cell 
[cellclicked.Button addTarget:self action:@selector(buttonClick2:) forControlEvents:UIControlEventTouchUpInside]; 

//Your Code 

}

您可以按照相同的步骤获得按钮 - (IBAction为) buttonClick2:(id)寄件人

现在你可以跟踪哪个按钮被点击并更改该按钮的方法。

并声明你的手机和按钮

相关问题