tableview reloadData doesn't work... - NSArray invalid summary
I have read a lot of posts about this topic, but i can't find an answer to fix my problem... For that reason I hope, you can help me:
I have got an iPad App with a SplitViewController Template. So the RootViewController is type of UITableViewController. My data is stored in two arrays, which are filled by a XMLParser (class SyncController). But the tableView doesn't show the data...
First my call of the parser in the AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the split view controller's view to the window and display.
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
syncController = [[SyncController alloc] init];
[syncController syncData];
return YES;
}
That works. The SyncController is parsing the XML and at the End, I have got two instance variables (NSMutableArrays) of the SyncController filled with my data, I want to transfer to my RootViewController:
rootViewController.visitorNames = [[NSArray alloc] initWithArray:self.visitorNames];
rootViewController.visitorCompanies = [[NSArray alloc] initWithArray:self.visitorCompanies];
[rootViewController.tableView reloadData];
reloadData seems to work:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"comp count: %u", [self.visitorCompanies count]);
return [self.visitorCompanies count]; }
The Console shows the right number of Elements... But then, cellForRowAtIndexPath isn't called
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"testghjgjggjgjggjghjghjghjghjghjghjjhgghj");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text = [self.visitorCompanies objectAtIndex:indexPath.row];
return cell;
}
There is no Console output. So I've set a breakpoint at numberOfRowsInSection to look at the instance Variables
Debug Output
They seem to be OK, but when you look at _dataSource of tableView, you see that there is an Invalid Summary...
I think that is the reason why my TableView doesn't work.
Info: If I don't use the SyncController and initialize the NSArrays with fixed values in RootViewControlle开发者_开发百科r's viewDidLoad, it works fine
As it works fine when you don't load the data via SyncController
, I think the data source for the table view is working fine and the output produced by NSLog()
suggests it too.
There must something wrong with SyncController
. Your code example is :
rootViewController.visitorNames = [[NSArray alloc]
initWithArray:self.visitorNames];
rootViewController.visitorCompanies = [[NSArray alloc]
initWithArray:self.visitorCompanies];
[rootViewController.tableView reloadData];
This code takes place in SyncController
, doesn't it ? And also :
// is self instance of SyncController, the app delegate ?
syncController = [[SyncController alloc] init];
// syncController.rootViewController = self.rootViewController ?
[syncController syncData];
Shouldn't you set this property before sync your data ?
Otherwise, if both your app delegate and your root view controller have properties named visitorNames
and visitorCompanies
, you should send your syncController
object a reference to your app delegate, in order to fill the arrays with some data.
You may also consult this SO question & answers : invalid summary problem while debugging in Xcode … Hope this helps.
精彩评论