私はグーグルで私の側から多くの研究を行って、なぜtableviewのreloadDataメソッドがうまくいかないかを調べました。データソースが設定されている、デリゲートが設定されている、テーブルビューがファイルの所有者に接続されているなどの可能なすべてのソリューションを確認しました。uitableView reloadDataがデリゲート、データソースとファイルの所有者接続を設定した後に機能しない
この後、私がテーブルビューをリロードしようとすると、行のメソッドが呼び出されますが、rowAtIndexPathのセルは呼び出されません。以下は私が書いたコードです。私はそれが動作しませんが、私はどのようにreloadData
作品を説明しよう理由を正確に言うことはできませんが、コードのこの部分から、間違った
- (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]に変更し、変更点を確認しました。私はデバッグし、最初のメソッドでは、配列rDataに結果を格納していることを確認しました。reloadDataメソッドはnoを呼び出します。私はrDataからコンテンツを印刷することができます。しかし、それはcellForRowIndexPathを呼び出すのではなく、もし私がテーブルビューをスクロールすると、データは配列rdataに全くありません。 – jeevangs
私が見ている唯一の説明は、テーブルは行を表示すべきではないと考えていることです。 numberOfSectionsから1を返し、numberOfRowsInSectionから1を返すので、常に1行が表示されます。 'rowHeight'プロパティは正しく設定されていますか? scrollviewのインセットによってセルが隠されていませんか? – Sulthan
右です。表示されるセルは1つだけで、セルは表示されます。それには問題はありません。私の唯一の懸案事項は、indexpathの行のセルが適切に呼び出されていないということです。とにかく、私はどこに間違っているのか理解しようとします。あなたが出くわしたら、私に知らせてください。 – jeevangs