Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果我们希望在同一个表视图控制器ios中使用静态单元格和动态单元格,那么在ios中如何实现这一点?_Ios_Objective C_Storyboard - Fatal编程技术网

如果我们希望在同一个表视图控制器ios中使用静态单元格和动态单元格,那么在ios中如何实现这一点?

如果我们希望在同一个表视图控制器ios中使用静态单元格和动态单元格,那么在ios中如何实现这一点?,ios,objective-c,storyboard,Ios,Objective C,Storyboard,我有一个tableViewController,在它下面我想要一个静态单元格,其余的都是动态单元格。我已经运行了动态单元格,但在同一个tableViewController中,我还需要添加一个静态单元格,如何实现它 请帮忙 提前感谢。您可以执行以下操作: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dynamicContent.

我有一个tableViewController,在它下面我想要一个静态单元格,其余的都是动态单元格。我已经运行了动态单元格,但在同一个tableViewController中,我还需要添加一个静态单元格,如何实现它

请帮忙


提前感谢。

您可以执行以下操作:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dynamicContent.count + 1; // +1 for the static cell at the beginning
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        // static cell
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StaticCellIdentifier" forIndexPath:indexPath];
        // customization
        return cell;
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DynamicCellIdentifier" forIndexPath:indexPath];
    id contentObject = self.dynamicContent[indexPath.row];
    // customization
    return cell;
}

不能在UITableViewController中同时创建静态单元格和动态单元格。
但是,您可以对静态单元格的数据进行硬编码,并在每次重新加载tableview时加载数据。

您可以将所有单元格保留在一个部分中,并不断检查索引路径。行==0或为它们创建单独的部分

typedef NS_ENUM(NSUInteger, TableViewSectionType) {
    TableViewSectionType_Static,
    TableViewSectionType_Dynamic
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2; // One for static cell, and another for dynamic cells
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    switch(section) {
        case TableViewSectionType_Static:
            return 1; // Always return '1' to show the static cell at all times.
        case TableViewSectionType_Dynamic:
            return [myDynamicData count];
    }
}

使用这种方法,您的单元格将分为两个部分,更易于管理。它将始终显示一个单元格,因为
TableViewSectionType\u Static
返回的行数始终为1。它将根据您的数据计数显示动态单元格。

据我所知,这是不可能的。你必须在你的CellForRowatineXpath中处理这种“行为”。顺便说一句。。。在这种情况下,静态单元格的确切含义是什么?静态单元格的意思是,无论表视图中是否有动态单元格,表视图中都有一个单元格