Recommendations for creating a table with dynamic data in iOS

I'm trying to create a table with dynamic data, and I'm kind of stuck. Here's how my data is structured:

NSMutableArray *bigArray;

bigArrayhas many elements NSDictionary.

each itemshas only one entry.

sectionName is the key, the value of NSMutableArray.

There valueare many objects in NSMutableArray.

I tried to explain it as simple as possible, here is the part that I'm stuck in.

//easy
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [bigArray count];
}

//medium
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{    
    // Return the number of rows in the section.
    return [[[[bigArray objectAtIndex:section] allValues] objectAtIndex:0] count];
}

I cannot understand this part, how to implement this method based on my current data structure:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView 
                             dequeueReusableCellWithIdentifier:@"MyCell"];

    MyObject *obj = //Need this part


    cell.textLabel.text = obj.name;   

    return cell;

}

Simply put, I'm trying to insert dynamic sections with dynamic data. I am looking for advice from more experienced developers, how would you handle this?

+3
source share
1 answer

, , , :

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
    }

    //this will get you the dictionary for the section being filled
    NSDictionary *item = [bigArray objectAtIndex:indexPath.section];
    // then the array of object for the section
    NSMutableArray *mutableArray = [item objectForKey:@"sectionName"];
    //you then take the object for the row
    MyObject *obj = [mutableArray objectAtIndex:indexPath.row];

    cell.textLabel.text = obj.name;   

    return cell;
}

0

All Articles