I set. When last cell displayed , add cell by threadProcess.
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
int nArrayCount;
nArrayCount=[self.mAppGameList count];
int row= (int)indexPath.row ;
if(row == nArrayCount)
{
if(mSearchGame_Thread != nil)
return;
NextSearchCell *searchCell =(NextSearchCell *)cell;
[searchCell.mActivityView startAnimating];
NSThread *searchThread = [[NSThread alloc] initWithTarget:self
selector:@selector(searchNextThreadProc:) object:tableView];
self.mSearchGame_Thread = searchThread;
[searchThread release];
[self.mSearchGame_Thread start];
// start new search ...
}
//thread method
-(void)searchNextThreadProc:(id)param
{
UITableView *tableView=(id)param;
NSMutableArray *newArray;
newArray=[NSMutableArray arrayWithArray:self.mAppGameList];
NSArray *pressedlist;
nArrayCount=[self.mAppGameList count];
.
.
.
[newArray addObject:item];
self.mAppGameList = newArray;
[tableView reloadData];
self.mSearchGame_Thread=nil;
}
This way is problem.
If I scroll table when tableview reload data, for a while tableview disappeared and appeard.
If I touch cell while adding next cell , sometimes it occur bad exc memory . I think, it call tableView: didSelectRowAtIndexPath: method before reloading new table. so, table's data is not.
So, I want to replace reload tableview way.Is there any way? please help me.
Instead of using reloadData, you can add the new rows by animation using this method in UITableView:
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
That way your view will not dissappear and reappear when reloading.
See this question: UITableView add cell Animation
Also make sure to perform any refreshments of the UI in the main thread by using:
[self performSelectorOnMainThread:@selector(refreshMethodName) withObject:nil waitUntilDone:NO];
A few comments about your code: