Ios 更新多节UITableView的单个节

Ios 更新多节UITableView的单个节,ios,uitableview,Ios,Uitableview,我在情节提要中创建了一个UITableViewController。它有两个部分。第一部分的行包含故事板中布置的控件。我想使用数组中的值更新第二部分中的行 我对iOS开发相当陌生。我了解如何使用UITableViewDataSource根据数组更新表,但不了解如何将更新限制到特定的节。谁能概述一下如何做到这一点 编辑这似乎是一个简单的问题,所以我想我的代码只会掩盖这个问题。也许我错了。以下是我所拥有的: MynumberOfRowsInSection函数在节中返回1,因为第一节(我在故事板中设计

我在情节提要中创建了一个
UITableViewController
。它有两个部分。第一部分的行包含故事板中布置的控件。我想使用数组中的值更新第二部分中的行

我对iOS开发相当陌生。我了解如何使用
UITableViewDataSource
根据数组更新表,但不了解如何将更新限制到特定的节。谁能概述一下如何做到这一点

编辑这似乎是一个简单的问题,所以我想我的代码只会掩盖这个问题。也许我错了。以下是我所拥有的:

My
numberOfRowsInSection
函数在节中返回1,因为第一节(我在故事板中设计的那一节)只有一行,否则它返回支持数据数组中的元素数:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
        return 1;
    else
        return [myData length];
}
如果节号为1,My
cellForRowAtIndexPath
函数将创建一个单元格。但我不知道如果区号是零该怎么办。如何避免重新创建我在故事板中布置的行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if(indexPath.section == 1)
   {
       cell.textLabel.text = [myData objectAtindex:indexPath.row]; 
   }
   else
   {
       // What to do here?
   }
}
在方法
-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
中添加以下内容

创建2个不同的UITableViewCells,并像这样引用它们

if (indexPath.section == 1) {
    NSString *CellIdentifier = @"DynamicCell";
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    //You are drawing your second section so you can use your array as values

    cell.property1...
    cell.property2...
    cell.property3...

    return cell;

}else{//If you have only 2 sections then else represent your first section
    //You are drawing your first section
    NSString *CellIdentifier = @"StaticCell";
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}
在方法
-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
中添加以下内容

创建2个不同的UITableViewCells,并像这样引用它们

if (indexPath.section == 1) {
    NSString *CellIdentifier = @"DynamicCell";
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    //You are drawing your second section so you can use your array as values

    cell.property1...
    cell.property2...
    cell.property3...

    return cell;

}else{//If you have only 2 sections then else represent your first section
    //You are drawing your first section
    NSString *CellIdentifier = @"StaticCell";
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}

可以在委托方法中更改行值

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
要识别该部分,只需使用:

indexPath.section

可以在委托方法中更改行值

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
要识别该部分,只需使用:

indexPath.section
您可以使用包含通缉部分中所有索引路径的数组,该数组使用循环和
NSMutableArray

您可以使用包含通缉部分中所有索引路径的数组,该数组使用循环和
NSMutableArray
构建

- (void)reloadSections:(NSIndexSet *)sections 
      withRowAnimation:(UITableViewRowAnimation)animation;
参数“
section
”是标识要重新加载的节的索引集



参数“
section
”是标识要重新加载的节的索引集。

如果在第一节中只有很少的静态控件,为什么不将这些控件放在表头视图中呢?因此,您只需要担心一个部分:)

如果在第一部分中只有很少的静态控件,为什么不将这些控件放在表头视图中呢?因此,您只需要担心一个部分:)

请更具体地说明您真正想要什么。请更具体地说明您真正想要什么。谢谢您的回复。我考虑过这种方法,但如果indexPath.section为零,我将返回什么?我不想以编程方式重新创建我在故事板中布置的行。第0节表示第一节。索引从0开始,所以第一节的第一行有indexath{0,0}我知道!当
indexPath.section==0
时,我返回什么?第一部分已经包含在故事板中创建的行。我不想以编程方式重新创建它们。如果section=0,则返回不带更改的单元格无效:“unchanged”单元格为空。我很确定iOS不能保证它传递到
cellForRowAtIndexPath
UITableViewCell
总是相同的。感谢您的回复。我考虑过这种方法,但如果indexPath.section为零,我将返回什么?我不想以编程方式重新创建我在故事板中布置的行。第0节表示第一节。索引从0开始,所以第一节的第一行有indexath{0,0}我知道!当
indexPath.section==0
时,我返回什么?第一部分已经包含在故事板中创建的行。我不想以编程方式重新创建它们。如果section=0,则返回不带更改的单元格无效:“unchanged”单元格为空。我很确定iOS不能保证它传递到
cellForRowAtIndexPath
UITableViewCell
总是相同的。我知道我可以通过编程实现这一点,但我找不到在故事板中将控件添加到标题的方法。这是可能的吗?我想如果你把一个空的uiview从对象库拖到情节提要中的tableview中,那就行了。那么用户可能需要将所有这些控件的样式设置为tableViewCells。比重新加载section@SimonMcLoughlin也许他把这些控件放在一个区域作为一种变通方法。它们不一定看起来像表行或其他什么。在这种情况下,标题视图将是一个更好的解决方案。顺便说一句,我想添加此答案作为对问题的评论,但似乎我没有必要的信誉点:)我知道我可以通过编程实现这一点,但我找不到在故事板中将控件添加到标题的方法。这是可能的吗?我想如果你把一个空的uiview从对象库拖到情节提要中的tableview中,那就行了。那么用户可能需要将所有这些控件的样式设置为tableViewCells。比重新加载section@SimonMcLoughlin也许他把这些控件放在一个区域作为一种变通方法。它们不一定看起来像表行或其他什么。在这种情况下,标题视图是更好的解决方案。顺便说一句,我想添加此答案作为对问题的评论,但似乎我没有必要的信誉点:)