从 SINGLE nsmutablearray 将数据添加到 UITableView 的 2 个部分

Posted

技术标签:

【中文标题】从 SINGLE nsmutablearray 将数据添加到 UITableView 的 2 个部分【英文标题】:Adding data to 2 Sections of UITableView from SINGLE nsmutablearray 【发布时间】:2009-09-28 12:04:14 【问题描述】:

我想知道如何在不同部分的 tableView 中列出数据,但来自单个数据源。

我看到的所有示例都有数组数 = 部分数。我想要的是假设我有一个 3d nsmutableArray。

If dArray.Id = 1  //add to first section of UITableView 
else add to Section 2 of UITableView.

它可能是可行的,但我只需要一个方向。

【问题讨论】:

【参考方案1】:

是的,这是可能的。

您可以拥有一个包含全部内容的 NSMutableArray (resultArray)。

那么在cellForRowAtIndexPath方法中你可以这样做

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    if(indexPath.section == 0)
    
        cell.text=[resultArray objectAtIndex:indexPath.row];
    
    else if(indexPath.section == 1)
    
        cell.text=[resultArray objectAtIndex:(indexPath.row+5)];
    
    else if(indexPath.section == 2)
    
         cell.text=[resultArray objectAtIndex:(indexPath.row+11)];
    

numberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section 

    NSInteger count;
    if(section == 0)
    
        count=6;
    
    else if(section == 1)
    
        count=6;
    
    else if(section == 2)
    
        count=4;
    
    return count;

【讨论】:

以上是关于从 SINGLE nsmutablearray 将数据添加到 UITableView 的 2 个部分的主要内容,如果未能解决你的问题,请参考以下文章

从 URL 将对象添加到 NSMutableArray 的更快方法

将 NSMutableArray 从模态视图控制器传递到父视图

如何将字符串从 NSMutableArray 传递给 double

无法将对象从块添加到 NSMutableArray

如何从 NSSet 返回 NSMutableArray

从 NSData 的 NSMutableArray 转换为 NSString 的 NSMutableArray?