UITableView在创建之后不会显示任何部分

时间:2010-12-06 12:59:51

标签: iphone objective-c uitableview

此处的相关代码:

-(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 dequeueReusableCellWithIdentifier:[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];
}

NSLog表示以下奇妙的条件:

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

抱歉超详细的问题。出了什么问题?

1 个答案:

答案 0 :(得分:0)

您的代码看起来是正确的。但是当你试图在- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return tmpDate; } 设置它时,tmpDate是否真的设置了?

您是否尝试过使用字符串?