原型单元和UITableView的问题
我有两种单元格,一种是标准标题字幕单元格,另一种是带有两个UITextField的自定义单元格。它们具有不同的标识符、视图和编辑 在我的代码中原型单元和UITableView的问题,uitableview,Uitableview,我有两种单元格,一种是标准标题字幕单元格,另一种是带有两个UITextField的自定义单元格。它们具有不同的标识符、视图和编辑 在我的代码中 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 我需要创建两种细胞。在任何时候,我只有一个单元格在编辑中,因此我创建一个NSUInteger,以跟踪正在编辑的单元格 我的代码如下所示: - (UI
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我需要创建两种细胞。在任何时候,我只有一个单元格在编辑中,因此我创建一个NSUInteger
,以跟踪正在编辑的单元格
我的代码如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell;
if ( rowInEdit == indexPath.row )
{
cell = [tableView dequeueReusableCellWithIdentifier:@"EDIT"];
if ( !cell )
{
cell = [[UITableViewCell alloc]init];
}
RLSite* site = [[RLSettings settings]siteAtIndex:indexPath.row];
[[cell textLabel]setText:site.name];
[[cell detailTextLabel]setText:site.url];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:@"VIEW"];
if ( !cell )
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"VIEW"];
}
RLSite* site = [[RLSettings settings]siteAtIndex:indexPath.row];
[[cell textLabel]setText:site.name];
[[cell detailTextLabel]setText:site.url];
}
return cell;
}
注意,我的第一部分肯定有缺陷。我不知道如何使用prototype创建单元,以及如何为其分配reuseIdentifier。此外,我不知道在创建单元格后如何访问该单元格中的UITextField
有人能帮我吗<代码>如何使用原型创建单元格您可以学习这些教程,因为我也从其中一个教程中学习了这些教程 教程
tableView:cellforrowatinexpath:
方法中超出它们
UITextField *txtField = (UITextField *)[cell viewWithTag:8];
这里用标记值替换8
)