如何在iPhone SDK中的TableView中实现"加载更多记录"?

mee*_*tpd 6 sqlite iphone objective-c iphone-sdk-3.0 ios4

我在数据库表中有10,000行.我有一个视图,假设在tableview中列出所有这些行.但是在一次拍摄中加载所需的时间需要很长时间才会出现在tableview

我们如何使用"加载更多记录"功能,一次可以获取20条记录?如果用户想要查看更多条目,可以单击"加载更多记录"按钮,它将显示接下来的20条记录.

将不得不修改我的select语句?为实现这一目标,我还需要做些哪些改变?

jak*_*kev 5

UITableView重用其单元格.这意味着您可以在cellForRowAtIndexPath:调用时动态访问数据库 - 您不需要一次加载所有10000个元素,也不应该.我希望这会有所帮助,而且我不会误解你的问题.

这是非常基本的UITableView的东西,但它应该让你开始.对不起,我对Core Data或SQLite了解不多.

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

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell-iPad" owner:self options:nil] lastObject];
        }
        else{
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] lastObject];
        }
    }


// Do stuff, load database values, etc

    return cell;
}
Run Code Online (Sandbox Code Playgroud)


mee*_*tpd 5

感谢大家的投入.但我能够使用以下链接实现这一点:

http://useyourloaf.com/blog/2010/10/2/dynamically-loading-new-rows-into-a-table.html

希望这对所有人都有用.