【发布时间】:2011-10-01 21:27:13
【问题描述】:
我已经阅读了很多关于这个主题的帖子,但我找不到解决我问题的答案......因此我希望你能帮助我:
我有一个带有 SplitViewController 模板的 iPad 应用程序。所以 RootViewController 是 UITableViewController 的类型。我的数据存储在两个数组中,由 XMLParser(SyncController 类)填充。但是tableView没有显示数据...
首先我在 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;
}
这行得通。 SyncController 正在解析 XML,最后,我有两个 SyncController 的实例变量 (NSMutableArrays) 填充了我的数据,我想转移到我的 RootViewController:
rootViewController.visitorNames = [[NSArray alloc] initWithArray:self.visitorNames];
rootViewController.visitorCompanies = [[NSArray alloc] initWithArray:self.visitorCompanies];
[rootViewController.tableView reloadData];
reloadData 似乎有效:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"comp count: %u", [self.visitorCompanies count]);
return [self.visitorCompanies count]; }
控制台显示正确数量的元素... 但是,cellForRowAtIndexPath 没有被调用
- (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;
}
没有控制台输出。 所以我在 numberOfRowsInSection 设置了一个断点来查看实例变量
它们看起来还可以,但是当你查看tableView的_dataSource时,你会看到有一个Invalid Summary...
我认为这就是我的 TableView 不起作用的原因。
信息:如果我不使用 SyncController 并在 RootViewController 的 viewDidLoad 中使用固定值初始化 NSArray,它可以正常工作
【问题讨论】:
标签: cocoa-touch uitableview nsarray datasource uisplitviewcontroller