reloadData not working with UITableView

I have some arrays which I update throughout my program and my UITableView needs to reflect these changes. I have the dataSource and delegate set properly because I can edit the UITableView. My problem is that when I call the reloadData function, nothing changes. I know my arrays have data in them because if I NSLog the count then I get more than 0.
I've put breakpoints in the UITableView controller and it looks like the reloadData is just getting ignored. The breakpoints only fire once when the view loads up, not when reloadData is called.
I'm declaring the UITableView in the header file like this

@interface FriendsTableController : UITableViewController {
IBOutlet UITableView * tblView;
}

Then in the .m file I've got this:
@synthesize tblView;

I'm trying to call the reloadData like this:
[tblView reloadData];

Have I over looked something?
Thanks,
Tom

Macbook 13.3", Mac OS X (10.5.6)

Posted on Dec 24, 2008 12:47 PM

Reply
47 replies

Dec 25, 2008 8:18 PM in response to bones237

bones237 wrote:
You're passing a message ("reloadData") to an object ("tblView") so therefore it needs to be in brackets.


[tblView reloadData];

The original poster did not know about the code markup tag that you used in your post, therefore he wound up linking to the contents of the code itself. That is, use code blocks: { code } and { /code }, without spaces. Proof: hover your mouse over the original post: it's a link! [And so is this, since I put it in brackets].

End of (possibly pointless) chastisement.

Message was edited by: andlabs

Message was edited by: andlabs

Dec 26, 2008 4:02 PM in response to harrytheshark

-(void)refreshTable:(NSArray)myArray:(NSArray*)mySecondArray:(NSArray*)myThirdArray:(NSArray)myForthArray {
//The "another" arrays are declared in the header file
anotherArray=myArray;
anotherSecondArray=mySecondArray;
anotherThirdArray = myThirdArray;
anotherForthArray = myForthArray;
NSLog(@"Refresh Table Function");
NSLog([NSString stringWithFormat:@"anotherArray count = %i",[anotherArray count]]);
[tblView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [anotherArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...

cell.text = [[NSString alloc] initWithFormat:@"Row %i)",indexPath.row];
return cell;
}

I know the function is getting called because the log displays the two messages and I know the anotherArray has objects because it says so in the log. It's just the reloadData that isn't working because the UITableView has no rows even after the reload call.
I know the table works because if I change the numberOfRowsInSection to return 10 then I get 10 rows of "Row 0", "Row 1" etc.

Thanks,
Tom

Message was edited by: harrytheshark

Dec 27, 2008 12:18 PM in response to navac

I put it in another classfile after the data for the table has been collected. Basically my apps signs into a website then grabs some data, I need this data to be displayed in the table. The app then updates the data every minute or so, so I need to be able to constantly reload the table.

The table has been formed before log in and data grabbing is complete, but I thought that a table could be reloaded at any time?

Tom.

Dec 27, 2008 10:20 PM in response to harrytheshark

As far as I know calling it constantly will not do the job. You should call it before you show your view, otherwise what you see on the screen will not be updated. I don't know how did you build your GUI in this regard, but I'd suggest you to rebuild the data array only and call reloadData only when you're going to push your view on the stack.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

reloadData not working with UITableView

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.