3
votes

I have two sections in tableview that is located inside tableviewcontroller For some reason the section value in method numberOfRowsInSection is always "1". Thats quite strange because, everything seems fine.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    int i=section;
    if(section==0)
        return 1;
    else{
        return [self.flightDetailsArray count];
    }
}

In storyboard i have a table with two sections

Ok, once again doing it for you to understand the problem. Watch this code

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.

    NSLog(@"Section: %d",(int)section);
    if(section==0)
        return 1;
    else{
        return [self.flightDetailsArray count];
    }
}

in Log i see "1" always what's that? its strange

3
That is unusual. Can you show how you know it's never 0?Droppy
I use debugger. I can even log it. but anyways its always "1"Jenya Kirmiza
I doubt that is the case, so can you please provide more evidence so we can see if you've missed something in your investigation.Droppy
i can provide the storyboard screen, Also note that its a UITableViewControllerJenya Kirmiza
I will try to recreate the sections, maybe its some bug with xcode. I tried to clean the project, didnt help.Jenya Kirmiza

3 Answers

0
votes

I dont understand the reason behind this due to the fact i'm also a beginner but as far as I'm concerned i think you're trying to return 1 row at first time and in the next step you want to return count of the flightDetailsArray so maybe you can achieve that by these steps :-

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    static int i=0
    if(i==0)
        return 1;
        i++;
    else{
        return [self.flightDetailsArray count];
    }


}
0
votes

I think that you want to return only 1 row in your 1st section and then the number of objects in your flightDetailsArrayin the second section. If that is the case, then just do this,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section==0)
        return 1;
    else{
        return [self.flightDetailsArray count];
    }
}

Now, it may be possible that your second section will also hold 1 row if there is only one object in your flightDetailsArray.

Please try to print NSLog(@"%@", [self.flightDetailsArray count]) and see the object number.

0
votes

Sorry, guys. The problem was that i used satic type of tableview, but had inside also dynamic cells. So i didn't pay attention to it. Then i changed id to dynamic, and added he dynamic sections and it worked just fine. Sorry for taking your time.