【问题标题】:Passing NSArray result from web service to a UITableViewController将 NSArray 结果从 Web 服务传递到 UITableViewController
【发布时间】:2012-11-22 12:48:36
【问题描述】:

对不起,如果这是一个重复的问题,但我似乎无法理解逻辑。

作为学习经验,我正在使用网络服务来填充 uitableview。基本上,我的 Web 服务返回一个数组数组,我希望将其传递给我的 UItableviewcontroller。我在一个单独的班级中有我的网络服务,我不确定如何传递数组。

这里的最佳做法通常是什么?

这是我的 WebService.m 文件:

#import "WebService.h"
#import "VaskerierTableViewController.h"

@implementation WebService

// Search the Laundrettes

-(void) searchLandrettes: (NSString*) SS {

        //create the service  
        SDZDevices2Api* service = [SDZDevices2Api service];
    service.logging = YES;

     // Returns NSMutableArray*.
    [service LocationFindSimple:self action:@selector(LocationFindSimpleHandler:) SearchString: SS Max: 25 BankId: [NSMutableArray array] BankName: [NSMutableArray array] Id: [NSMutableArray array] Name: [NSMutableArray array] Icon: [NSMutableArray array] Zip: [NSMutableArray array] Attributes: [NSMutableArray array]];

}

// Handle the response from LocationFindSimple.

 - (void) LocationFindSimpleHandler: (id) value {

     // Handle errors
     if([value isKindOfClass:[NSError class]]) {
             NSLog(@"%@", value);
         return;
     }

     // Handle faults
      if([value isKindOfClass:[SoapFault class]]) {
         NSLog(@"%@", value);
         return;
      }

      // Do something with the NSString* result
          NSArray* result = (NSArray*)value;
      NSLog(@"LocationFindSimple returned the string-value: %@", result);

          // Antal arrays i alt
          int arrayCount = [value count];
          NSLog(@"ArrayCont = %i", arrayCount);

     /*
      * Første array indeholder kun taksten "OK"
      * De efterfølgende synes at indeholde 6 elementer
      * Derfor opretter jeg 6 array, til det indhold, som jeg synes at kunne finde
      */

     if (arrayCount > 1) {

         // Blot til test
         NSLog(@"test = %@", [value objectAtIndex:1]);

         // Et array til hver type information, for hvert resultat
         NSArray *bankId = [[NSArray alloc] initWithArray:[value objectAtIndex:1]];
         NSArray *bankName = [[NSArray alloc] initWithArray:[value objectAtIndex:2]];
         NSArray *iId = [[NSArray alloc] initWithArray:[value objectAtIndex:3]];
         NSArray *name = [[NSArray alloc] initWithArray:[value objectAtIndex:4]];
         NSArray *icon = [[NSArray alloc] initWithArray:[value objectAtIndex:5]];
         NSArray *zip = [[NSArray alloc] initWithArray:[value objectAtIndex:6]];
         NSArray *attributes = [[NSArray alloc] initWithArray:[value objectAtIndex:7]];
    }
}
@end

【问题讨论】:

    标签: ios uitableview nsarray


    【解决方案1】:

    使用类函数从 WebserviceManager 中获取返回的数组。在视图的视图控制器的 viewdidLoad 中调用该函数。

    尝试低于概念。 在您的 WebserviceManager 类中

    +(NSMutableArray *)getArrayFromWebservice { ........ 返回返回数组; }

    在 viewController 的 viewdidLoad 中调用该函数并放松你的 tableview。

    更新 1: 勾选“+”号表示这是Objective C上的类方法,所以你可以直接使用类名来调用它。

    例如

    self.list = [WebserviceManager getArrayFromWebservice];

    【讨论】:

    • 您好,感谢您的回复。我不确定“使用类函数从 WebserviceManager 获取返回的数组”是什么意思。我得到了编写返回数组的类方法的逻辑。但我不确定如何访问它。可能只是这里的新手误会......
    • self.list = [WebserviceManager getArrayFromWebservice];
    猜你喜欢
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多