Skip to main content

uitableView reloadData doesn"t work after setting delegate, datasource and file"s owner connection



I have googled and done lot of research from my side to find out why the reloadData method on tableview wouldn't work. I checked all the possible solutions like the datasource is set, delegate is set, the tableview is connected to the file's owner.





After all these, when I am trying to reload the tableview, the no. of rows method gets called, but the cell for rowAtIndexPath doesn't get called. Below is the code that I have written. Please let me know, where I am going wrong







- (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];

}




Comments

  1. From this part of code I cannot say exactly why it does not work but I'll try to explain how reloadData works.

    First, how UITableView works: basically, it's a scrollview. When it is drawn, it checks how many rows it has, then checks their height and from its size and scroll position it decides which rows are currently displayed. Then it asks the delegate to return a UITableViewCell for every displayed row.
    When the table is scrolled, it removes the hidden cells from the view hierarchy and adds the cells that have appeared.

    And now the tricky part - what does reloadData do? It just removes all the UITableViewCells from the table hierarchy. Nothing more. The actual update is done when the table is drawn for the first time after reloadData.

    So, my suggestion is - check that your table is not hidden and check its frame. Also, I see that you are accessing both a property getter self.tripsTableView and an ivar tripsTableView. This is confusing. Do they both return the same?

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex