2

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

Jenya Kirmiza
  • 385
  • 1
  • 3
  • 12

3 Answers3

0

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];
    }


}
tryKuldeepTanwar
  • 3,490
  • 2
  • 19
  • 49
  • i want the first section to contain 1 row, and the second section [self.flightDetailsArray count] but for some reason section is always "1" numberOfRowsInSection:(NSInteger)section I mean the param of this method. – Jenya Kirmiza Jul 29 '16 at 11:42
0

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.

Natasha
  • 6,651
  • 3
  • 36
  • 58
0

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.

Jenya Kirmiza
  • 385
  • 1
  • 3
  • 12