前几天做项目的时候遇见了一个问题,就是当点击某个cell时,要改变当前选中cell的text,后来找出了解决办法,其实很简单,
下边的这个方法是必须要执行的方法,大家可以发现如果可以获取到indexPath,就可以找到当前的cell了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
大家都知道点击cell时会执行下面的这个代理方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
index = indexPath;
//可以再这里获取点击cell的indexPath,这样就可以搞定了
}
下边的两行代码就是修改点击的cell的text
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:index];
cell.textLabel.text= @"ok";