gpt4 book ai didi

ios - 当我在其上滚动并在其底部完成时,将单元格添加到我的 tableView

转载 作者:行者123 更新时间:2023-11-28 22:11:29 24 4
gpt4 key购买 nike

我在 UIViewController 中有一个 tableView。当我加载 viewController 时,正在加载带有 3 个单元格的 tableView。每次我在我的 tableView 上滚动并在它的底部完成时,我希望它被添加到它(其他)3 个单元格。 Facebook 应用程序究竟如何!请帮帮我!这是我在代码中遇到的情况(未添加单元格):

    -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//I created an int flag because this method (as soon as it initialize the
//table) is called 2 times (because when it load the viewController, is called
// the method that populates the arrays that contain the details to be shown in
// the cells and reload the tableView)
if (_flagCells == 0 || _flagCells == 1) {
_flagCells ++;
return;
}

if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){

//phpClass is a class that contain scripts used to connect my app to script php for mySQL DB
//objsRequest is a method of phpClass that receive a query for input and return an array of //results of that query. cellsLimit represent the cells to be shown (Once every 3 to 3) and //numberOfDequeuedCells represent the number of cells to be added (every 3) that is SELECT .. //FROM .. LIMIT 0,3 .... LIMIT 3,3 .... LIMIT 6,3 ....
[_arrID addObjectsFromArray:[_phpClass objsRequest:[NSString stringWithFormat:@"SELECT ID FROM mii LIMIT %d,%d",_cellsLimit,_numberOfDequeuedCells]]];

for (int i = (int)[_arrID count]-3; i < [_arrID count]; i++) {

//objRequest is a method of phpClass that receive a query for input and return a string that
//represent the result of that query
[_arrNames addObject:[_phpClass objRequest:[NSString stringWithFormat:@"SELECT Name FROM mii WHERE ID = %@",_arrID[i]]]];
[_arrGen addObject:[_script objRequest:[NSString stringWithFormat:@"SELECT Gen FROM mii WHERE ID = %@",_arrID[i]]]];

//getImg is a method of phpClass that receive the user ID for input and return an image
//representing the user image
UIImage *img = [_phpClass getImg:_arrID[i]];
[_arrImgs insertObject:img atIndex:i];

//Here is the problem because the rows doesn't be added to my tableView
[_tableView beginUpdates];
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];

}
_cellsLimit +=3;
[_tableView endUpdates];
}
}

最佳答案

我前段时间自己做过。如果我没记错的话,我只是将额外的数据加载到我用作表中数据容器的数组中。加载数据后,我会重新绘制表格。就是这样。

我认为您只是因为尝试将其做得更复杂而迷路了。

至于你的评论:

[_tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.001];

 [_tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

两者都应在另一个线程中执行 reloadData,因此不应导致循环。但是,即使那样,您也应该在到达表末尾之前添加新数据。

关于ios - 当我在其上滚动并在其底部完成时,将单元格添加到我的 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22816109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com