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

时间:2015-04-18 15:35:47

标签: ios json nsmutablearray nsarray

我有一个代码,我修改了从外部JSON文件中提取数据。有两个NSArrays。一个用于图像,一个用于颜色。然后,当按下特定数组时,它会打开一个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];

}

0 个答案:

没有答案