【问题标题】:UITableView in UIViewController reloadData not updating table viewUIViewController reloadData 中的 UITableView 不更新表格视图
【发布时间】:2011-11-19 16:18:21
【问题描述】:

我有一个 UIViewController 类的 MainViewController,在这个视图中我有一个表格视图和另一个嵌入其中的视图。如您所见,我将表视图委托添加到视图控制器。

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,   UITableViewDataSource, UITableViewDelegate> {

现在我的问题已经在互联网上多次搜索中被问了大约 50 次,但我仍然无法找到解决方案。

为什么 reloadData 不起作用...?

我正在从 XML 提要下载信息,并从应用委托刷新提要:

- (void)applicationDidBecomeActive:(UIApplication *)application

我已经插入了多个 NSLog,这是我发现的。来自 XML 提要的刷新数据没有问题。但是表格视图单元格没有被刷新。

我在里面放了一个 NSLog:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

虽然数据正在刷新,但是当我调用 [tableView reloadData];永远不会调用 cellForRowAtIndexPath。

我希望有人可以帮助我解决这个问题,我已经在这个问题上工作了大约 12 个小时,但没有运气。我已经用尽了多个网站上的搜索按钮......

仅供参考: - 表视图在 Interface Builder 中连接。

-我的表格正在通过 TableViewCells 逐个加载,遵循 Apple 示例,从 Table View Programming guide 的第 51 页开始。

附加代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 17;
}

感谢您的帮助

【问题讨论】:

    标签: uitableview uiviewcontroller reloaddata


    【解决方案1】:

    你有示例代码吗?

    我的第一个想法:

    • 数据源未连接
    • 节中的行返回 0
    • 部分回馈 0

    【讨论】:

    • Mafis,我在上面添加了一些关于你提到的项目的额外代码。我的表视图数据源和委托连接到 XIB 文件中的文件所有者。
    【解决方案2】:

    现在一切正常...这对我来说浪费了很多时间...

    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
    [_mainViewController refresh];
    [_mainViewController.tableView reloadData];
    }
    
    - (void)refresh {
    Parser *xmlParser = [[Parser alloc] init];
    [xmlParser parseRssFeed:@"http://www.somesite.com/file.xml" withDelegate:self];
    [xmlParser release];
    [self.tableView reloadData];
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-21
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多