Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将NSArray转换为NSMutable以动态删除字符串_Ios_Json_Nsmutablearray_Nsarray - Fatal编程技术网

Ios 将NSArray转换为NSMutable以动态删除字符串

Ios 将NSArray转换为NSMutable以动态删除字符串,ios,json,nsmutablearray,nsarray,Ios,Json,Nsmutablearray,Nsarray,我修改了一段代码,从外部JSON文件中提取数据。这里有两种情况。一个用于图像,一个用于颜色。然后,当按下特定数组时,它会打开一个webviewcontroller。我让它工作得很好。问题就在这里。我希望能够随时修改JSON,并让应用程序更新信息,但由于NSArray信息是硬编码的,如果我从JSON中删除objectforkey,我不知道如何删除数组。任何帮助都将不胜感激 调用图像和颜色的代码为: - (IBAction)onclick:(id)sender { NSArray *images

我修改了一段代码,从外部JSON文件中提取数据。这里有两种情况。一个用于图像,一个用于颜色。然后,当按下特定数组时,它会打开一个webviewcontroller。我让它工作得很好。问题就在这里。我希望能够随时修改JSON,并让应用程序更新信息,但由于NSArray信息是硬编码的,如果我从JSON中删除objectforkey,我不知道如何删除数组。任何帮助都将不胜感激

调用图像和颜色的代码为:

- (IBAction)onclick:(id)sender {


NSArray *images = @[

                    [UIImage imageNamed:[NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"PhoneUrl"]]],
                    [UIImage imageNamed:[NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"TextUrl"]]],
                    [UIImage imageNamed:[NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"MailUrl"]]]
                    ];
NSArray *colors = @[
                    [UIColor [NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"PhoneColor"]],
                    [UIColor [NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"TextColor"]]],
                    [UIColor [NSString stringWithFormat: @"%@",[dataDictionary objectForKey:@"MailColor"]]],
                   ];

Sidebar *callout = [[Sidebar alloc] initWithImages:images  borderColors:colors];
callout.delegate = self;
[callout show];
}

然后当按下时,它调用以下命令:

- (void)sidebar:(Sidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {

self.webViewController = [[PBWebViewController alloc] init];

PBSafariActivity *activity = [[PBSafariActivity alloc] init];
self.webViewController.applicationActivities = @[activity];
self.webViewController.excludedActivityTypes = @[UIActivityTypeMail, UIActivityTypeMessage];

NSLog(@"Tapped item at index %lu",(unsigned long)index);
if (index == 0) {

     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dataDictionary objectForKey:@"PhoneWeb"]]];
     [sidebar dismissAnimated:YES completion:nil];

}

if (index == 1) {

    if(![MFMessageComposeViewController canSendText]) {

        UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [warningAlert show];

        return;

    }
   NSArray *recipents = @[[dataDictionary objectForKey:@"TextWeb"]];
    MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
    messageController.messageComposeDelegate = self;
    [messageController setRecipients:recipents];
    [[messageController navigationBar] setTintColor:[UIColor whiteColor]];
   [self presentViewController:messageController animated:YES completion:nil];

    [sidebar dismissAnimated:YES completion:nil];

}


if (index == 2) {

    if ([MFMailComposeViewController canSendMail])

    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
       [[mailer navigationBar] setTintColor:[UIColor whiteColor]];
        mailer.mailComposeDelegate = self;
        NSArray *toRecipients = [NSArray arrayWithObjects:[dataDictionary objectForKey:@"MailWeb"], nil];
        [mailer setToRecipients:toRecipients];
        [self presentViewController:mailer animated:YES completion:nil];

    }

    else

    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                 message:@"Your device doesn't support the composer sheet"
                              delegate:nil
                              cancelButtonTitle:@"OK"
                               otherButtonTitles: nil];

        [alert show];



    }
    [sidebar dismissAnimated:YES completion:nil];

}

修改JSON的触发器是什么(或者更确切地说,知道它何时发生)?只需重新运行代码来加载JSON。我不明白你的问题是什么?如果你说JSON,你是指dataDictionary?如果希望NSArray*图像和NSArray*颜色可变,为什么要声明它们?我的web主机上的JSON文件会调用应用程序中要使用的图像名称和颜色。我正在使用未列出数据字典的其他人的预制代码。他们将图像名称和颜色硬编码。我将其更改为从JSON文件调用文件,但我不知道如何转换数组并使其可变,以便可以在后端对其进行修改并动态更改应用程序。