0

我正在使用单例类进行 Web 服务调用并在 uitableview 中显示,我的功能是当我单击新果园名称的提交按钮以进行新添加然后查看重定向到 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];
}
4

1 回答 1

0

您没有使用 theConnection 的返回结果。(至少不在您提供的代码中。)由于您已将您的类设置为委托,因此请实现 NSURLConnectionDataDelegate 方法。

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

使用它将您的 JSON 数据保存到 NSArray,然后您可以在 UITableView 中使用它。

如果您异步发送请求,请不要忘记附加数据

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

于 2013-11-01T14:53:47.420 回答