如何在UITableViewController中添加静态单元格的自定义?

时间:2017-12-17 06:15:33

标签: ios objective-c uitableview

我正在使用UITablViewContoller和静态单元格。我在故事板中设计了静态单元。我需要在其中一个单元格中添加动态列表。我正在尝试使用自定义单元格。我没有得到结果。 我在UITableViewController中使用下面的代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 7){
    CommentTableViewCell *cell = (CommentTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CommentTableViewCell"];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CommentTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    return cell;
}
else{
    // This part causes the problem. Not sure what to pass here. Without else part it throws error.
    static NSString *simpleTableIdentifier = @"SimpleTableCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }


    return cell;
    }
 }

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 return 9; // number of static cells in storyboard
}

0 个答案:

没有答案
相关问题