我在tableview中有两个部分位于tableviewcontroller内
由于某种原因,方法numberOfRowsInSection中的节值始终为“1”。那很奇怪,因为一切似乎都很好。
- (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];
}
}
在情节提要中,我有一张桌子,分为两个部分
好的,再次执行此操作以使您了解问题。观看此代码
- (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];
}
}
在日志中,我总是看到“1”
那是什么?真奇怪
最佳答案
由于我也是初学者,因此我不了解其背后的原因,但就我而言,我认为您是第一次尝试返回1行,而在下一步中,您想返回flightDetailsArray,所以也许您可以通过以下步骤实现:
- (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];
}
}