Ios UITableview第三次未加载数据?
我不知道该怎么办。但我加载了数据并在加载数据时加载了表Ios UITableview第三次未加载数据?,ios,objective-c,uitableview,afnetworking,Ios,Objective C,Uitableview,Afnetworking,我不知道该怎么办。但我加载了数据并在加载数据时加载了表 [manager POST:path parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) { arryGlobal = [NSMutableArray new]; [arryGlobal addObject:responseObject]; if([[[[arryGlobal valueForKey:@"Su
[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服务时,它加载了数据,获取了数据,成功地重新加载了表,但它并没有改变表中的内容,它在第二次调用时的样子是一样的
那么那里发生了什么??当我滚动表格时,我用来传递表格的cellforrowatinedexpath
数组中包含第二次调用Webservice的数据
编辑:
我在其他视图中添加了此表视图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];
试试这个
if([[[[arryGlobal valueForKey:@"Success"] objectAtIndex:0] stringValue] isEqualToString:@"1"])
{
[arryGlobal removeAllObjects];
arryGlobal=[NSarray alloc]init];
arryGlobal = [[arryGlobal valueForKey:@"Result"] objectAtIndex:0];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tblMainCategory reloadData];
});
}
块:success()已在主队列中运行;您不需要使用dispatch_async(dispatch_get_main_queue();
arryGlobal是一种NSMutableArray;为什么要使用名为“thevalueforKey:”的函数来获取值?
我想也许你应该打印responseObject来检查你的数据好的,那么下面的错误是:
[self.bgViewCat insertSubview:objMain.view atIndex:1];
我用这个代替它,一切都很好,不知道为什么
[self.bgViewCat addSubview:objMain.view];
您创建一个新数组,将响应对象添加到其中,然后如果响应对象中的某个内容与某个内容匹配,则替换该数组?这很难看。该数组的最佳做法是什么?@DxAndroid,请更新您的代码结构,如果响应发生更改,它随时可能崩溃。您确定在第三次尝试时收到的数据是正确的吗mpt与从第二次尝试中收到的数据不同?请尝试禁用缓存。这可能是导致问题的原因。P.s是arryGlobal全局变量?没有调度,get_main_队列也不工作。是的,它是全局变量。您通过函数[arryGlobal valueForKey:@“Success”]得到了什么?\u弱类型(self)weakself=self;[manager POST:path参数:参数成功:^(NSURLSessionDataTask*task,id responseObject){if([[[[[responseObject valueForKey:@“success”]objectAtIndex:0]stringValue]IseQualtString:@“1”]){arryGlobal=[[responseObject valueForKey:@“Result”]objectAtIndex:0];[weakself.tblMainCategory reloadData];}失败:^(NSURLSessionDataTask*任务,NSError*错误)NSLog(@“错误:%@,[error localizedDescription]);};尝试此
\u弱类型(self)weakself=self;[manager POST:路径参数:参数成功:^(NSURLSessionDataTask*任务,id responseObject){if([[[[responseObject valueForKey:@“Success”]objectAtIndex:0]stringValue]IseQualtString:@“1”]){arryGlobal=[[responseObject valueForKey:@“Result”]objectAtIndex:0];[weakself.tblMainCategory重载数据];}}失败:^(NSURLSessionDataTask*任务,NSError*错误){NSLog(@“Error:%@,[Error localizedDescription];}];
并从arryGlobal中删除所有对象,它在第三行崩溃,因为其中没有数据。如果(!(arryGlobal==nil | |[arryGlobal count]==0)){[arryGlobal removeAllObjects];}