Ios 方法调用后在tableView中重新加载数据

Ios 方法调用后在tableView中重新加载数据,ios,uitableview,reloaddata,Ios,Uitableview,Reloaddata,我有一种从服务器获取数据以用于表中的方法,问题是当数据被提取时,若数组中已经有3个项目,然后在方法调用后变成5个,我们重新加载数据,那个么它会复制记录 [self saveData]; [self setUpData]; [tableView reloadData]; - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1 ; } - (NSInteger)tableView:(UI

我有一种从服务器获取数据以用于表中的方法,问题是当数据被提取时,若数组中已经有3个项目,然后在方法调用后变成5个,我们重新加载数据,那个么它会复制记录

[self saveData];
[self setUpData];
[tableView reloadData];


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


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];

    int count=[resultArray count];

    NSLog(@"resultArry Row Counts is %d",count);

    return [resultArray count];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 70.00;
}


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

    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";

    CustomCellF *cell = (CustomCellF *)[tableView
                                        dequeueReusableCellWithIdentifier: CustomCellIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellF"
                                                     owner:self options:nil];
        for(id oneObject in nib)
            if ([oneObject isKindOfClass:[CustomCellF class]])
                cell = (CustomCellF *)oneObject;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }

    appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
    FeedbackData *theCellData = [resultArray objectAtIndex:indexPath.row];

    cell.theTitle.text =theCellData.user_Feedback;

    NSString*type=theCellData.user_Rating;

    if ([type isEqualToString:@"One Star"]) {

        cell.theCellImage1.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage2.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage3.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage4.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage5.image=[UIImage imageNamed:@"stargray.png"];
    }
    else if ([type isEqualToString:@"Two Stars"]) {

        cell.theCellImage1.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage2.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage3.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage4.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage5.image=[UIImage imageNamed:@"stargray.png"];
    }
    else if ([type isEqualToString:@"Three Stars"]) {

        cell.theCellImage1.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage2.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage3.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage4.image=[UIImage imageNamed:@"stargray.png"];
        cell.theCellImage5.image=[UIImage imageNamed:@"stargray.png"];
    }
    else if ([type isEqualToString:@"Four Stars"]) {

        cell.theCellImage1.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage2.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage3.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage4.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage5.image=[UIImage imageNamed:@"stargray.png"];
    }
    else {

        cell.theCellImage1.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage2.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage3.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage4.image=[UIImage imageNamed:@"starblue.png"];
        cell.theCellImage5.image=[UIImage imageNamed:@"starblue.png"];
    }

    return cell;
}

如果您想先重新填充阵列,请将其设为零,以避免您现在面临的问题

if(dataArray!=nil){
dataArray=nil;
dataArray=[[NSMutableData alloc]init];
}

与调用方法(setUpData)时一样,您将获得两次相同的数据,或者在其中添加新数据

您需要它来删除所有旧数据并使用新的数据集,为此,您需要从数组中删除/释放所有数据并向其中添加新对象

在方法中(如果使用圆弧)


如果你想重新填充你的数组,那么首先你必须清空它

     if(resultArray.count >0)
     {
              [resultArray removeAllObjects];
      }

然后重新填充阵列。

首先释放阵列:

[dataArray release];
或者如果您使用
Arc
,则

[dataArray removeAllObjects];
然后再次检查并填充

if(dataArray!=nil){
    dataArray=nil;
    dataArray=[[NSMutableData alloc]init];
}

你想要什么?删除重复性?如果数据重复,则向我们显示更多代码,这意味着您没有清空模型(数组)是要删除duplicacy@AnoopVaidya是的,你是对的,怎么做
if(dataArray!=nil){
    dataArray=nil;
    dataArray=[[NSMutableData alloc]init];
}