UITableView displays no sections altough they are created
Relevant code here:
-(UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
{
UITableViewCell *cell;
NSInteger currentRow = 0;
for (int i = 0; i < [indexPath section]; i++) {
currentRow += ((sectionNumber*) [numSections objectAtIndex:i]).num;
}
currentRow += [indexPath row];
NSLog(@"[current row] %d", currentRow);
//if (lineFound == YES){
cell = [tableView dequeueReusableCellWithI开发者_如何学Cdentifier:[NSString stringWithFormat:@"%d", currentRow]];
if (cell == nil){
[[NSBundle mainBundle] loadNibNamed:@"pathResultsCell" owner:self options:nil];
cell = pathCell;
self.pathCell = nil;
PathTimesRow *myRow = [resultArray objectAtIndex:currentRow];
NSString * img = [myRow.LineOperatingCompanyID stringByAppendingString:@".gif"];
companyImg.image = [UIImage imageNamed:img];
line.text=myRow.LineName;
source.text= myRow.StartPlaceFullName;
dest.text=myRow.EndPlaceFullName;
if (myRow.DepDateTime != myRow.FirstPlaceDepDateTime)
TimeS.text = @"*";
TimeS.text=[TimeS.text stringByAppendingString:[[myRow.DepDateTime substringFromIndex:11] substringToIndex:5]];
TimeD.text=[[myRow.ArrDateTime substringFromIndex:11] substringToIndex:5];
tmpDate=[[NSString alloc]initWithString:[myRow.DepDateTime substringToIndex:10]];
NSLog(@"[PathSearchResult]date: %@", myRow.DepDateTime);
}
// }
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return tmpDate;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"sections %d", countSections);
if (countSections > 1) {
NSLog(@"this is the number of sections", countSections);
return countSections;
}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (countSections>1) {
NSLog(@"section %d", section);
sectionNumber * tmp= [numSections objectAtIndex:section];
NSLog(@"rows %d", tmp.num);
return tmp.num;
}
return [resultArray count];
}
The NSLog's indicate the following wonderful condition:
2010-12-06 14:55:13.531 iBusILp[9467:207] sections 7
2010-12-06 14:55:13.533 iBusILp[9467:207] this is the number of sections
2010-12-06 14:55:13.534 iBusILp[9467:207] section 6
2010-12-06 14:55:13.534 iBusILp[9467:207] rows 1
2010-12-06 14:55:13.534 iBusILp[9467:207] section 0
2010-12-06 14:55:13.535 iBusILp[9467:207] rows 1
2010-12-06 14:55:13.539 iBusILp[9467:207] section 1
2010-12-06 14:55:13.540 iBusILp[9467:207] rows 1
2010-12-06 14:55:13.540 iBusILp[9467:207] section 2
2010-12-06 14:55:13.541 iBusILp[9467:207] rows 1
2010-12-06 14:55:13.542 iBusILp[9467:207] section 3
2010-12-06 14:55:13.542 iBusILp[9467:207] rows 2
2010-12-06 14:55:13.544 iBusILp[9467:207] section 4
2010-12-06 14:55:13.545 iBusILp[9467:207] rows 1
2010-12-06 14:55:13.545 iBusILp[9467:207] section 5
2010-12-06 14:55:13.545 iBusILp[9467:207] rows 3
2010-12-06 14:55:13.546 iBusILp[9467:207] [current row] 0
2010-12-06 14:55:13.550 iBusILp[9467:207] [PathSearchResult]date: 2010-12-06T19:00:00+02:00
2010-12-06 14:55:13.550 iBusILp[9467:207] [current row] 1
2010-12-06 14:55:13.552 iBusILp[9467:207] [PathSearchResult]date: 2010-12-07T19:00:00+02:00
2010-12-06 14:55:13.553 iBusILp[9467:207] [current row] 2
2010-12-06 14:55:13.556 iBusILp[9467:207] [PathSearchResult]date: 2010-12-08T19:00:00+02:00
2010-12-06 14:55:13.556 iBusILp[9467:207] [current row] 3
2010-12-06 14:55:13.558 iBusILp[9467:207] [PathSearchResult]date: 2010-12-09T19:00:00+02:00
2010-12-06 14:55:13.559 iBusILp[9467:207] [current row] 4
2010-12-06 14:55:13.561 iBusILp[9467:207] [PathSearchResult]date: 2010-12-09T20:00:00+02:00
2010-12-06 14:55:14.863 iBusILp[9467:207] [current row] 5
2010-12-06 14:55:14.865 iBusILp[9467:207] [PathSearchResult]date: 2010-12-10T15:00:00+02:00
2010-12-06 14:55:14.879 iBusILp[9467:207] [current row] 6
2010-12-06 14:55:14.882 iBusILp[9467:207] [PathSearchResult]date: 2010-12-11T19:00:00+02:00
2010-12-06 14:55:14.896 iBusILp[9467:207] [current row] 7
2010-12-06 14:55:14.898 iBusILp[9467:207] [PathSearchResult]date: 2010-12-11T20:00:00+02:00
2010-12-06 14:55:14.944 iBusILp[9467:207] [current row] 8
2010-12-06 14:55:14.947 iBusILp[9467:207] [PathSearchResult]date: 2010-12-11T21:30:00+02:00
2010-12-06 14:55:14.961 iBusILp[9467:207] [current row] 9
2010-12-06 14:55:14.964 iBusILp[9467:207] [PathSearchResult]date: 2010-12-12T19:00:00+02:00
2010-12-06 14:55:15.161 iBusILp[9467:207] [current row] 6
2010-12-06 14:55:15.164 iBusILp[9467:207] [PathSearchResult]date: 2010-12-11T19:00:00+02:00
2010-12-06 14:55:15.429 iBusILp[9467:207] [current row] 5
2010-12-06 14:55:15.432 iBusILp[9467:207] [PathSearchResult]date: 2010-12-10T15:00:00+02:00
Sorry for the super detailed question. What is going wrong?
Your code looks correct. But is tmpDate really set when you are trying to set it in - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return tmpDate;
}
?
Have you tried just using a string?
精彩评论