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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.