【发布时间】:2017-07-08 09:24:09
【问题描述】:
当我点击表格视图单元格时,我需要更改另一个单元格的详细标签文本。 我该怎么做?
【问题讨论】:
标签: ios uitableview cocoa-touch
当我点击表格视图单元格时,我需要更改另一个单元格的详细标签文本。 我该怎么做?
【问题讨论】:
标签: ios uitableview cocoa-touch
您需要为所选行存储 indexPath。您可以在 cellForRow 中放置一个大致相同的条件。
这是排序示例:
在.h文件中声明变量:
int selectedIndexPath;
.m
-(void)viewDidLoad
{
[super viewDidLoad];
// So it won't show any select for the first time
selectedIndexPath = -1;
[tableView reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int currentRow = (int)indexPath.row;
if(currentRow == selectedIndexPath)
{
// Show your base cell
}
else
{
// Show detail cell
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndexPath = (int)indexPath.row;
[tableView reloadData];
}
【讨论】: