iOS,iTableView在我重新加载新数据后闪烁 发生了什么事

iOS,iTableView在我重新加载新数据后闪烁 发生了什么事,ios,objective-c,Ios,Objective C,我有一个UITableView,我要做的是显示数据库中的前十条记录,然后当用户滚动到最后时,我只从数据库中检索一条记录,然后将其添加到数组并重新加载数据,但UITableView似乎在闪烁。我添加了一些代码,可以正确地同步数据,这样当我向下滚动并检索记录时,就不会得到重复的数据 问题: 向UITableView添加新数据时,如何停止闪烁 代码 这是我向下滚动到底部时添加新数据的地方: -(void)renderScrollThreadInfo:(NSDictionary*

我有一个UITableView,我要做的是显示数据库中的前十条记录,然后当用户滚动到最后时,我只从数据库中检索一条记录,然后将其添加到数组并重新加载数据,但UITableView似乎在闪烁。我添加了一些代码,可以正确地同步数据,这样当我向下滚动并检索记录时,就不会得到重复的数据

问题: 向UITableView添加新数据时,如何停止闪烁

代码 这是我向下滚动到底部时添加新数据的地方:

            -(void)renderScrollThreadInfo:(NSDictionary*)dic{

            NSDictionary *thread = [dic objectForKey:@"thread"];


            if((NSNull*)thread != [NSNull null]){

            int t_ID;
                int t_U_ID;
                int t_C_ID;
                NSString *t_Name;
                NSString *t_Description;
                NSDate *t_Created;
                int t_Flagged;
                int t_Rated;
                NSString *firstName;
                NSString *lastName;
                NSString *categoryName;

                for(NSDictionary *dict in thread)
                {
                if((NSNull *)[dict objectForKey:@"T_ID"] != [NSNull null]){
                t_ID = [[dict objectForKey:@"T_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_U_ID"] != [NSNull null]){
                t_U_ID = [[dict objectForKey:@"T_U_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_C_ID"] != [NSNull null]){
                t_C_ID = [[dict objectForKey:@"T_C_ID"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_Name"] != [NSNull null]){
                t_Name = [dict objectForKey:@"T_Name"];
                }
                if((NSNull *)[dict objectForKey:@"T_Description"] != [NSNull null]){
                t_Description = [dict objectForKey:@"T_Description"];
                }
                if((NSNull *)[dict objectForKey:@"T_Created"] != [NSNull null]){
                NSString *timestampString = [dict objectForKey:@"T_Created"];
                double timestampDate = [timestampString doubleValue];
                t_Created = [NSDate dateWithTimeIntervalSince1970:timestampDate];
                }
                if((NSNull *)[dict objectForKey:@"T_Flagged"] != [NSNull null]){
                t_Flagged = [[dict objectForKey:@"T_Flagged"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"T_Rated"] != [NSNull null]){
                t_Rated = [[dict objectForKey:@"T_Rated"] intValue];
                }
                if((NSNull *)[dict objectForKey:@"U_FirstName"] != [NSNull null]){
                firstName = [dict objectForKey:@"U_FirstName"];
                }
                if((NSNull *)[dict objectForKey:@"U_LastName"] != [NSNull null]){
                lastName = [dict objectForKey:@"U_LastName"];
                }
                if((NSNull *)[dict objectForKey:@"C_Name"] != [NSNull null]){
                categoryName = [dict objectForKey:@"C_Name"];
                }

                ThreadInfo *threadObj = [ThreadInfo new];
                threadObj.iD = t_ID;
                threadObj.userId  = t_U_ID;
                threadObj.catId = t_C_ID;
                threadObj.name = t_Name;
                threadObj.description = t_Description;
                threadObj.timeStampCreated = t_Created;
                threadObj.flagged = t_Flagged;
                threadObj.rated = t_Rated;
                threadObj.firstName = firstName;
                threadObj.lastName = lastName;
                threadObj.category = categoryName;

                BOOL foundThreadId = false;

                for(int i = 0; i < [threadsArray count] - 1; i++){
                ThreadInfo *tmpThreadInfo = (ThreadInfo*)[threadsArray objectAtIndex:i];
                if(tmpThreadInfo.iD == t_ID){
                    foundThreadId = true;
                }
                }

                if(!foundThreadId){
                [threadsArray addObject:threadObj];
                }



            }
            [tableViewThreads reloadData];
            }

        }
这是a使用数据设置自定义单元格的代码:

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


            if(tableViewThreads == tableView){
            NSString *cellIdentifier = @"cell";
            ThreadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


            ThreadInfo *threadInfo = (ThreadInfo*)[self.threadsArray objectAtIndex:indexPath.row];;
            if (cell == nil)
            {
                cell = [[ThreadTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

                [cell setupView:threadInfo];

            }


            cell.labelFirstName.text = [NSString stringWithFormat:@"%@ %@", threadInfo.firstName,threadInfo.lastName];

            cell.labelTimestamp.text = [NSDateFormatter localizedStringFromDate:threadInfo.timeStampCreated dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];
            cell.labelTimestamp.text = [cell.labelTimestamp.text stringByReplacingOccurrencesOfString:@"AM" withString:@""];
            cell.labelTimestamp.text = [cell.labelTimestamp.text stringByReplacingOccurrencesOfString:@"PM" withString:@""];

            cell.labelThreadName.text = threadInfo.name;
            //cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;

            }
            if(tableViewPosts == tableView){
            NSString *cellIdentifier = @"cell2";
            PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

            PostInfo *postInfo = (PostInfo*)[self.postsArray objectAtIndex:indexPath.row];
            if (cell == nil)
            {
                cell = [[PostTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

                [cell setupView:postInfo];
            }



            cell.labelUserName.text = [NSString stringWithFormat:@"%@ %@ posted...", postInfo.firstName,postInfo.lastName];
            cell.labelCreated.text = [NSDateFormatter localizedStringFromDate:postInfo.timeStampCreated dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];
            cell.labelCreated.text = [cell.labelCreated.text stringByReplacingOccurrencesOfString:@"AM" withString:@""];
            cell.labelCreated.text = [cell.labelCreated.text stringByReplacingOccurrencesOfString:@"PM" withString:@""];
            cell.labelMessage.text = postInfo.message;
            return cell;
            //[cell.contentView addSubview:[self setupThreadItem:threadInfo]];
            }

            return nil;
        }

当您收到新数据时,使用
[UITableView insertRowsAtIndexPaths:(NSArray*)InExpaths with RowAnimation:(UITableViewRowAnimation)animation

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


            if(tableViewThreads == tableView){
            NSString *cellIdentifier = @"cell";
            ThreadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


            ThreadInfo *threadInfo = (ThreadInfo*)[self.threadsArray objectAtIndex:indexPath.row];;
            if (cell == nil)
            {
                cell = [[ThreadTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

                [cell setupView:threadInfo];

            }


            cell.labelFirstName.text = [NSString stringWithFormat:@"%@ %@", threadInfo.firstName,threadInfo.lastName];

            cell.labelTimestamp.text = [NSDateFormatter localizedStringFromDate:threadInfo.timeStampCreated dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];
            cell.labelTimestamp.text = [cell.labelTimestamp.text stringByReplacingOccurrencesOfString:@"AM" withString:@""];
            cell.labelTimestamp.text = [cell.labelTimestamp.text stringByReplacingOccurrencesOfString:@"PM" withString:@""];

            cell.labelThreadName.text = threadInfo.name;
            //cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;

            }
            if(tableViewPosts == tableView){
            NSString *cellIdentifier = @"cell2";
            PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

            PostInfo *postInfo = (PostInfo*)[self.postsArray objectAtIndex:indexPath.row];
            if (cell == nil)
            {
                cell = [[PostTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

                [cell setupView:postInfo];
            }



            cell.labelUserName.text = [NSString stringWithFormat:@"%@ %@ posted...", postInfo.firstName,postInfo.lastName];
            cell.labelCreated.text = [NSDateFormatter localizedStringFromDate:postInfo.timeStampCreated dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterMediumStyle];
            cell.labelCreated.text = [cell.labelCreated.text stringByReplacingOccurrencesOfString:@"AM" withString:@""];
            cell.labelCreated.text = [cell.labelCreated.text stringByReplacingOccurrencesOfString:@"PM" withString:@""];
            cell.labelMessage.text = postInfo.message;
            return cell;
            //[cell.contentView addSubview:[self setupThreadItem:threadInfo]];
            }

            return nil;
        }