我知道你不能在一个UITableView个单元中混合静态和动态单元类型,但我想不出更好的方式来描述我的问题.

我有几个具有固定内容的预定细胞,我也有未知数量的细胞,它们位于中间.所以我想让我的桌子看起来像这样:

Fixed
Fixed
Fixed
Dynamic
Dynamic
Dynamic
Dynamic
Dynamic
Fixed
Fixed

那么,你到底建议我如何在我的cellForRowAtIndexPath方法中实现这一点呢?

谢谢

推荐答案

正如你所说,你不能混合静态和动态细胞.但是,您可以将内容分解为与每个组对应的不同数据array.然后将表拆分为不同的部分,并从CellForRowatineXpath:中的正确数组加载数据.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"CELLID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

    switch (indexPath.section) {
        case 0:{
            cell.textLabel.text = self.arrayOfStaticThings1[indexPath.row];
        }break;

        case 1:{
            cell.textLabel.text = self.arrayOfDynamicThings[indexPath.row];
        }break;

        case 2:{
            cell.textLabel.text = self.arrayOfStaticThings2[indexPath.row];
        }break;

        default:
            break;
    }

    return cell;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:{
            return self.arrayOfStaticThings1.count;
        }break;

        case 1:{
            return self.arrayOfDynamicThings.count;
        }break;

        case 2:{
            return self.arrayOfStaticThings2.count;
        }break;

        default:
            return 0;
            break;
    }
}

Objective-c相关问答推荐

如何限制 UITextField 中的特殊字符(点和下划线除外)?

如何判断 iPhone 现在在哪个位置(横向或纵向)?

让 NSRunLoop 等待设置标志的最佳方法?

MKMapView zoom 到 viewDidLoad 上的用户位置?

在 iOS 中检测 PAN 手势的方向

将 CSS 插入 UIWebView / WKWebView 中加载的 HTML

自动布局和按下时隐藏底栏

烦人的[Environment: Sandbox]提示

适用于 ios 的 360° 全景库

Objective C const NSString * vs NSString * const

在运行时判断 iOS 版本?

在 ios8 中没有调用 didRegisterForRemoteNotificationsWithDeviceToken,但是 didRegister...Settings 是

从 NSMutableString 中删除最后一个字符

如何在 UIImageView 中显示 base64 图像?

在 Objective C 中,你能判断一个对象是否具有特定的属性或消息吗?

UITextField:键盘出现 timeshift 动视图

自定义导航栏样式 - iOS

既然我正在使用 Core Data,如何对我的模型进行单元测试?

如何设置 NSPredicate 来查找具有 nil 属性的对象

如何在键盘上添加完成按钮?