我在一个Controller中有2个UITableViews.每个表都有自己的单元原型,其中包含UITableViewCell的不同子类:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == self.commentsTable){
CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommentCell"];
cell.message.text = @"test";
}else if(tableView == self.paramsTableView){
RealtyParamCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RealtyParamCell"];
cell.label.text = @"test2";
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我在最后一行收到错误return cell;:"使用未定义的标识符单元格"但我无法cell在开头定义:
UItableViewCell *cell;
if(tableView == self.commentsTable){
<...>
}
Run Code Online (Sandbox Code Playgroud)
因为我需要精确的细胞类 - CommentCell或者RealtyParamCell
好吧,你仍然可以cell在开始时定义
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UItableViewCell *cell;
if(tableView == self.commentsTable){
CommentCell *commentCell= [tableView dequeueReusableCellWithIdentifier:@"CommentCell"];
commentCell.message.text = @"test";
cell = commentCell;
}else if(tableView == self.paramsTableView){
RealtyParamCell *realtyParamCell = [tableView dequeueReusableCellWithIdentifier:@"RealtyParamCell"];
realtyParamCell.label.text = @"test2";
cell = realtyParamCell;
}
return cell;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70 次 |
| 最近记录: |