简体   繁体   English

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

[英]Adding data to 2 Sections of UITableView from SINGLE nsmutablearray

I wanted to know how to list data in tableView in different sections BUT from a single datasource. 我想知道如何在一个数据源的不同部分列出tableView中的数据。

All examples i saw had number of arrays = number of sections. 我看到的所有例子都有数组=节数。 What i want is suppose I have a 3d nsmutableArray. 我想要的是假设我有一个3d nsmutableArray。

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

Its probably dooable, but i jus need a direction. 它可能是可行的,但我需要一个方向。

Yeah it is possible to do it. 是的,有可能做到这一点。

You can have a single NSMutableArray ( resultArray ) with the entire content in it. 您可以拥有一个包含整个内容的NSMutableArrayresultArray )。

Then in the cellForRowAtIndexPath method you can do it this way 然后在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)];
    }
}

and in numberOfRowsInSection 并在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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM