我正在使用单例类进行Web服务调用并在uitableview中显示,我的功能是当我点击新的orchardname的提交按钮进行新添加然后查看重定向到tableview但是看不到最近添加的数据。 “singOrchard.orcharsList”它是我必须显示的果园名称数组。 “[wOrchrad getorchardslist]”这是我的网络服务电话。
- (IBAction)Submit:(id)sender
{
if (Orchadname.text.length == 0) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"DataTree" message:@"Please Enter OrchardName" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[message show];
}
else {
[singOrchard.orcharsList removeAllObjects];
NSString *urlStr = [NSString stringWithFormat:@"http://xyz.com"]; // Passing token to URL
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; // Support to perform URLrequest
if (theConnection) { // checking connection successfull or not
webData1 = [NSMutableData data];
NSLog(@"Orchard Name is %@", Orchadname.text);
}
[wOrchrad getorchardslist];
NSLog(@"ARRAY COUNT %@",singOrchard.orcharsList);
[self performSelector:@selector(gotodetails) withObject:nil afterDelay:4];
}
}
“[wOrchard getorchardslist] - Singletone + Webserviceutility”
- (void)getorchardslist
{
orchardsnames = [[NSMutableArray alloc] init];
singltoneclass = [SingletoneClass sharedInstanceMethod];
theRequest =[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.xyz.com"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
webData = [NSMutableData data];
[theConnection start];
}
答案 0 :(得分:0)
您没有使用theConnection的返回结果。 (至少不在您提供的代码中。)由于您已将类设置为委托,因此请实现NSURLConnectionDataDelegate方法。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
使用它将您的JSON数据保存到NSArray,然后可以在UITableView中使用它。
如果您发送请求异常,请不要忘记使用
附加数据- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data