从NSMutableArray在UIViewController上执行基于ObjectAtIndex的操作

时间:2016-05-09 13:49:09

标签: ios objective-c json nsmutablearray

这是一个有趣的问题。我有一个应用程序,我有一个JSON文件,应用程序ping几个"对象"由此JSON文件定义。该应用程序在UITableViewController上执行此操作。但是,我正在构建AtAGlance视图以显示ping测试失败的对象。这个AtAGlance实际上将存在于第一个VC上。话虽这么说,我已经完成了序列化JSON和我获得良好价值的所有设置。但是,我不确定如何指定发送ping的ObjectAtIndex。有关如何从objectAtIndex的数组中指定UIViewController的任何想法?这可能是一个非常愚蠢的问题,但过去几天我已经尝试了所有的事情。

这里有一些代码供您查看,如果您需要任何其他代码,请与我们联系。

self.objectsList = [[NSArray alloc] init];
[[HTTPServices instance] getConnectabilityObject:^(NSArray * _Nullable dataArray, NSString * _Nullable errorMessage) {
    if (dataArray) {
        NSMutableArray *array = [[NSMutableArray alloc] init];

        for (NSDictionary *dictonary in dataArray) {
            ConnectabilityObject *object                = [[ConnectabilityObject alloc] init];
            object.ConnectabilityTitle                  = [dictonary objectForKey:@"ConnectabilityObjectTitle"];
            object.ConnectabilityFullIPAddress          = [dictonary objectForKey:@"ConnectabilityObjectFullIPAddress"];
            object.ConnectabilityObjectLastOctet        = [dictonary objectForKey:@"ConnectabilityObjectLastOctet"];
            object.ConnectabilityObjectType             = [dictonary objectForKey:@"ConnectabilityObjectType"];
            object.ConnectabilityObjectPortNumberOne    = [dictonary objectForKey:@"ConnectabilityObjectPortNum1"];
            object.ConnectabilityObjectPortNumberTwo    = [dictonary objectForKey:@"ConnectabilityObjectPortNum2"];
            object.ConnectabilityObjectPortNumberThree  = [dictonary objectForKey:@"ConnectabilityObjectPortNum3"];
            [array addObject:object];
        }
        self.objectsList = array;
    } else if (errorMessage) {
        UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:@"Uh oh" message:@"We just had a crash landing into the nest. We couldn't grab the connectivity file...try again later" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:^(UIAlertAction *dismiss){
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
        [errorAlert addAction:dismissAction];
        [self presentViewController:errorAlert animated:YES completion:nil];
    }
}];

0 个答案:

没有答案