【问题标题】:Correct operation of Table View and Table Detail ViewTable View和Table Detail View的正确操作
【发布时间】:2010-08-31 06:25:35
【问题描述】:

我需要一点帮助。在我的项目中有一个标签栏。在其中一个标签栏项目上有一个导航控制器,在视图上有一个表格视图。

对于 TableViewController 有常用的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [myData count];
}

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// here the DetailViewController is activated
}

DetailViewController 的构造与 TableViewController 类似。与 TableView 所选行相关的数据将作为 SQL 查询的关键数据,然后将其结果存储在一个数组中。唯一的区别是我使用这个:

viewWillAppear:包含和SQL查询,然后将结果加载到数组sqlQueryResult中。

- (void)viewWillDisappear:(BOOL)animated {
        while( [sqlQueryResult count] >0 )           
[sqlQueryResult removeObjectAtIndex:0];
}

这在显示 DetailView 表时第一次起作用。但是,如果我们返回 TableView 并选择不同的行,DetailView 会出现,但以下内容不会再次运行(因为它们已经这样做了): numberOfSectionsInTableView: 或 tableView:(UITableView *)tableView numberOfRowsInSection: 。我在文档中读到有些方法只被调用一次 - 但是我没有看到这些方法的评论。

如何“重置”TableView?或者我应该调用什么方法来设置它的行数/节数?

【问题讨论】:

    标签: iphone uitableview uinavigationcontroller refresh


    【解决方案1】:

    我相信您正在寻找的是:

    [self.tableView reloadData];
    

    您基本上需要向您的 tableView 发送“reloadData”消息。然后它会再次调用你的方法来刷新它的内容。

    【讨论】:

    • 感谢这个简短而有用的回答!我会尝试使用这种方法。
    猜你喜欢
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多