【问题标题】:Working with dynamic and static sections together in a tableview在表格视图中一起使用动态和静态部分
【发布时间】:2014-05-26 18:27:38
【问题描述】:

我在管理表格视图中的单元格时遇到了一些问题。

我有一个包含两个部分的表格视图: 第一个,我有 3 个自定义单元格,带有静态单元格。

第二个,我有一个动态类型。

要使用动态的,没有问题发生,但静态的,我不知道如何“重用”它们。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexpath.section = 0){
        //here is the question, how to return the stactis that had already been defined
    }else{
        return cell //here is okay, i can return the dynamic
}

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
         if(indexpath.section = 0){
             //here is the question, how to return the stactis that had already been defined
             static NSString *CellIdentifier = @"StaticCell";
    
             StaticCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
             return cell;
    
    
         }else{
    
            static NSString *CellIdentifier = @"DynamicCell";
    
             UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
             if(cell == nil){
                cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
             }
             return cell;
         }
    

    【讨论】:

    • 所以 3 个静态单元格中的每一个,我都需要放置一个标识符吗?我所做的动态的不同但工作正常
    猜你喜欢
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多