我从webservice获取一些数据。并将该数据加载到包含5个图像的tableview,并将一些字符串数据完美地加载到tableview中。但当用户点击butoon点击一次aagain再次调用webservcie。并再次在该tableview中加载该数据。
我想再次阻止重复加载。我怎么能这样做
我试图在用户点击按钮时保存,在NsuserDefault中保存密钥。然后检查weathe是否存在密钥没有调用webservice,如果没有预设密钥,则不要调用webservice,但它在tablview中显示为空白。密钥保存在NsDictionary之后。
代码在这里。
-(void)btnCliked
{
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"%@",[delegate.def objectForKey:@"Check"]);
if([delegate.def objectForKey:@"Check"])
{
}
else
{
delegate.str= [delegate.imgurl stringByAppendingString:@"getappdata.php"]; // Get data through php file
NSLog(@"%@",delegate.str);
NSURL * url=[NSURL URLWithString:delegate.str];
NSData * data=[NSData dataWithContentsOfURL:url];
NSError * error;
//Get json data in Dictionary
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];
NSLog(@"%@",json);
NSLog(@"%@",delegate.firstArray);
NSArray * responseArr = json[@"Deviceinfo"];
for(NSDictionary * dict in responseArr)
{
[delegate.firstArray addObject:[dict valueForKey:@"Appname"]];
[delegate.secondArray addObject:[dict valueForKey:@"Description"]];
[delegate.thirdArray addObject:[dict valueForKey:@"Icon"]];
[delegate.fourthArray addObject:[dict valueForKey:@"Link"]];
}
NSLog(@"%@",delegate.firstArray);
NSLog(@"%@",delegate.secondArray);
NSLog(@"This is image path array %@",delegate.thirdArray);
NSLog(@"this is App Link Array %@",delegate.fourthArray);
[delegate.def setObject:delegate.firstArray forKey:@"Check"];
[delegate.def synchronize];
}
GetMoreAppsViewController * gmavc=[[GetMoreAppsViewController alloc]initWithNibName:@"GetMoreAppsViewController" bundle:nil];
[self.navigationController pushViewController:gmavc animated:YES];
}
我怎么能解决这个问题。
提前感谢..
答案 0 :(得分:0)
这样做
1)将此变量声明为全局
NSDictionary *json
2)单击按钮时首先检查此变量
if(json==nil)
{
// call web service
}