0
votes


I'm looking for the best possible solution for a complex UITableView.

What I want :
I have an arbitrary number of sections.
In this section is just one static cell and then should come any number of dynamic cells.

My Data are stored in some NSMutableArray and i tried somethink like this:
Combine static and prototype content in a table view
But i dont know how to handle it with my kind of problem. So can somebody give me a hint or a best practice?
UPDATE: 1
http://jsfiddle.net/konstheinrich188/HKkA8/ Fiddle shows how my data looks and what im trying todo

This pic shows how i want to code my tableview...
What i want

3
Your problem would seem identical so what issues did you have implementing the solution from the other question? - Wain
I dont know how to create x sections with different type of cells.. My thinking is : foreach item in myArray create a section. Foreach section add one static cell and [myotherArray count] dynamic cells ... - Konstantin Heinrich
Why not an array of arrays? Outer array is sections and each inner array is the dynamic rows for the section... - Wain
You can use the tableView delegate method: -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [self.myArray count];} to create the sections you need. Use this in conjuction with the answer in the thread you read - Raúl Juárez
What you're calling a static cell, isn't static, since it will have a different name for each section, and so you still need to get its content from your data structure. To get the number of rows in each section, you're going to have to add the count of elements in SubItem and SubItem 2 Plus 1 for the title cell (the one you're calling static). Trying to use your data structure to populate a table is going to be convoluted, so I would probably parse that data first into an array of arrays to make it simpler. - rdelmar

3 Answers

1
votes

When you are using the term "static", are you really talking about a "uitableview static cell", or rather "cell with static content"? If the former; why do you need that? If the latter; how about testing in each section whether this is the first cell in the section, and then presenting static content? For all other cells, display dynamic content:

if (indexPath.row == 0) {
    // First row in section. Display static content
    ...
} else {
    // Display dynamic content
    ...
}

For what purpose do you need the static cells?

1
votes

So after a while and some testing and listen to your ideas and technicals i solved my problem!
Here is a little code :

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

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

    UISprint*s = [mappedSprints objectAtIndex:section];
    return s._name;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    UISprint* s = [mappedSprints objectAtIndex:section];
    return [s.internalUserStorey count] + [s.externalUserStorey count] + 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 130;
    }
    return 80;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell%d%d", indexPath.row, indexPath.section]];

            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Cell%d%d", indexPath.row, indexPath.section]];
            }

    UISprint*s = [mappedSprints objectAtIndex:indexPath.section];


    if (indexPath.row == 0) {
        //Here is my first cell 
        //cell.textLabel.text =s._name;


    }
    else if(indexPath.row >= 0 && indexPath.row<=[s.internalUserStorey count]){

       //here are the cells for SubItem


    }

    else if(indexPath.row >= [s.internalUserStorey count]){


    //here are the cells for SubItem 2   

    }
    return cell;


So thanks to all !! Best Konstantin

-1
votes

You can take one NSMuatableArray and add references on that i.e.

NSMuatableArray *arr=[NSMuatableArray alloc]init];

//section no 1 
[arr addObject:@"2"]; 

//section no 2 
[arr addObject:@"1"];

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

   switch(arr objectAtIndex[indexPath.row])
  {
  } 
}

you can use this way by using references you want set cells.