【发布时间】:2016-03-29 09:08:11
【问题描述】:
不知道该怎么办。但是我在加载数据时加载了数据和加载表,
[manager POST:path parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
arryGlobal = [NSMutableArray new];
[arryGlobal addObject:responseObject];
if([[[[arryGlobal valueForKey:@"Success"] objectAtIndex:0] stringValue] isEqualToString:@"1"]){
arryGlobal = [[arryGlobal valueForKey:@"Result"] objectAtIndex:0];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tblMainCategory reloadData];
});
}
else if([[[[arryGlobal valueForKey:@"Success"] objectAtIndex:0] stringValue] isEqualToString:@"0"]){
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
//here is place for code executed in error case
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error while sending"
message:@"Sorry, try again."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
NSLog(@"Error: %@", [error localizedDescription]);
}];
它两次完美运行,但是当我第三次调用此 Web 服务时,它会加载数据、获取数据、成功重新加载表格,但它不会更改表格中的内容,它会显示为第二次。
那么那里会发生什么?当我滚动表格时,在我用来传入表格的cellForRowAtIndexPath 数组中包含第二次称为 Web 服务的数据。
编辑:
我在其他视图中添加了这个表视图 VievController:
MainCategory *objMain = [[MainCategory alloc] initWithNibName:@"MainCategory" bundle:nil];
[objMain LoadData:tag];
objMain.view.frame = CGRectMake(0, 0, self.bgViewCat.frame.size.width, self.bgViewCat.frame.size.height);
[self.bgViewCat insertSubview:objMain.view atIndex:1];
[self addChildViewController:objMain];
[objMain didMoveToParentViewController:self];
【问题讨论】:
-
您创建一个新数组,将响应对象添加到其中,然后如果响应对象中的某些内容匹配您然后替换数组?太丑了。
-
那里的最佳做法是什么?
-
@DxAndroid,请更新你的代码结构,如果响应有变化,它随时可能崩溃。
-
您确定第 3 次尝试收到的数据与第 2 次尝试收到的数据不同吗?也尝试禁用缓存。也许这就是导致问题的原因。
标签: ios objective-c uitableview afnetworking