【问题标题】:tableview reloadData doesn't work... - NSArray invalid summarytableview reloadData 不起作用... - NSArray 无效摘要
【发布时间】: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 设置了一个断点来查看实例变量

Debug Output

它们看起来还可以,但是当你查看tableView的_dataSource时,你会看到有一个Invalid Summary...

我认为这就是我的 TableView 不起作用的原因。

信息:如果我不使用 SyncController 并在 RootViewController 的 viewDidLoad 中使用固定值初始化 NSArray,它可以正常工作

【问题讨论】:

    标签: cocoa-touch uitableview nsarray datasource uisplitviewcontroller


    【解决方案1】:

    当您不通过SyncController 加载数据时它工作正常,我认为表格视图的数据源工作正常,NSLog() 生成的输出也表明了这一点。

    SyncController 一定有问题。您的代码示例是:

    rootViewController.visitorNames = [[NSArray alloc]
                                       initWithArray:self.visitorNames];
    rootViewController.visitorCompanies = [[NSArray alloc]
                                           initWithArray:self.visitorCompanies];
    [rootViewController.tableView reloadData];
    

    这段代码发生在SyncController,不是吗?还有:

    // is self instance of SyncController, the app delegate ?
    syncController = [[SyncController alloc] init];
    // syncController.rootViewController = self.rootViewController ?
    [syncController syncData];
    

    您不应该在同步数据之前设置此属性吗?

    否则,如果您的应用委托和根视图控制器都具有名为 visitorNamesvisitorCompanies 的属性,您应该向您的 syncController 对象发送对您的应用委托的引用,以便用一些数据填充数组.

    您也可以参考这个 SO 问题和答案:invalid summary problem while debugging in Xcode … 希望这会有所帮助。

    【讨论】:

    • 缺少的属性 rootViewController 是解决方案。 syncController.rootViewController = self.rootViewController
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    相关资源
    最近更新 更多