我已經從我身邊搜索了很多研究,並找出了爲什麼tableview上的reloadData方法不起作用。我檢查了所有可能的解決方案,如數據源設置,代理設置,tableview連接到文件的所有者。uitableView reloadData在設置委託,數據源和文件的所有者連接後不起作用
畢竟這些,當我試圖重新加載tableview,沒有。行方法被調用,但rowAtIndexPath單元格不會被調用。以下是我寫的代碼。請讓我知道,我要去的地方錯了
- (void)onReservationListSuccess:(NSArray *)rData
{
if (rData != nil)
{
resList = [[NSArray alloc] initWithArray:rData];
if([resList count] > 0)
{
[self.tripsTableView reloadData];
//[self.tripsTableView beginUpdates];
//[self.tripsTableView reloadSections:[NSIndexSet indexSetWithIndex:0]
// withRowAnimation:UITableViewRowAnimationNone];
//[self.tripsTableView endUpdates];
}
else
{
[tripsTableView reloadData];
[tripsTableView setHidden:YES];
[noTripsLabel setHidden:NO];
}
}
if(fsnNeedsRefresh == YES)
{
[[NSNotificationCenter defaultCenter] postNotificationName:UpdateFSNList object:nil];
fsnNeedsRefresh = NO;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int temp=[resList count];
NSLog(@"The no. of rows are %d", temp);
NSLog(@"Testing Purpose");
NSLog(@"The pnr details of the object is:%@",((TripData *)[resList objectAtIndex:0]).pnrDescription);
return 1;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"The cell for the row at indexpath is getting called");
static NSString *CellIdentifier = @"TripCellIdentifier";
TripCell *cell = (TripCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TripCell" owner:self options:nil];
for(id oneObject in nib)
if([oneObject isKindOfClass:[TripCell class]])
cell = (TripCell *)oneObject;
}
// Set up the cell...
TripData *tripData = (TripData *)[resList objectAtIndex:indexPath.row];
cell.pnrLabel.text = tripData.pnr;
NSLog(@"The cell text is %@",tripData.pnr);
cell.pnrDescriptionLabel.text = tripData.pnrDescription;
NSLog(@"The cell text is %@",tripData.pnrDescription);
cell.pnrTypeLabel.text = tripData.pnrType;
NSLog(@"The cell text is %@",tripData.pnrType);
if(checkInAllowed)
{
cell.checkInButton.tag = indexPath.row;
[cell.checkInButton addTarget:self action:@selector(checkIn:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
[cell.checkInButton setEnabled:NO];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller
TripData *tripData = (TripData *)[resList objectAtIndex:indexPath.row];
NSLog(@"%@", tripData.pnr);
if(tripData != nil)
{
TripOverviewViewController *tripOverviewViewController = [[TripOverviewViewController alloc] initWithTrip:tripData];
[self.navigationController pushViewController:tripOverviewViewController animated:YES];
[tripOverviewViewController release];
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
非常感謝您的解釋。我確實將上面的行更改爲[tripsTableView reloadData]和dint查看任何更改。我調試並發現,在第一種方法中,我將一些結果存儲在數組rData中,並且reloadData方法調用no。行,我可以從rData打印內容。但它不是調用cellForRowIndexPath,如果我滾動tableview,數組rdata中根本沒有數據。 – jeevangs 2012-02-24 21:06:49
我看到的唯一解釋是表格認爲沒有行應該顯示。你從numberOfSections返回1,從numberOfRowsInSection返回1,所以應該總是顯示1行。 rowHeight屬性設置是否正確?不是由scrollview插入隱藏的單元格? – Sulthan 2012-02-24 21:19:23
你是對的。只有1個單元格必須顯示,並且單元格可見。沒有問題。我唯一擔心的是,indexpath中的行的單元格沒有正確調用。無論如何,我會試圖找出我要去哪裏錯了。如果你遇到,請告訴我。 – jeevangs 2012-02-24 21:43:08