UIAlertview故障/错误

时间:2014-06-24 17:10:39

标签: ios objective-c xcode

我正在创建一个应用程序,我不知道为什么我会收到此错误。

error picture http://i61.tinypic.com/kalnk2.png

我不知道该怎么办。当我单击确定时,我收到此错误:(这是整个错误)

http://pastebin.com/raw.php?i=BEeGbjJ8

我不明白问题是什么,我看了很多答案,然而,似乎都没有。我的代码是:

 @implementation AJSettingsViewController
-(NSString*) dataFilePath{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [path objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:FILENAME];
}

-(void) saveFile{
        NSMutableArray *array = [[NSMutableArray alloc] init];
        [array addObject:country];
    [array addObject:state];
    [array addObject:town];
    [array addObject:zipcode];
    [array addObject:name];



        [array writeToFile:[self dataFilePath] atomically:YES];


    //[array dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    zipcodetextfield.translatesAutoresizingMaskIntoConstraints = NO;

    [view setTranslatesAutoresizingMaskIntoConstraints:NO];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)zipcodelookup:(id)sender{
        [zipcodetextfield resignFirstResponder];
    zipcodetextfield.translatesAutoresizingMaskIntoConstraints = NO;

            zipcode = zipcodetextfield.text;
    if(zipcode.length >0){

        NSString *url = [NSString stringWithFormat:@"http://ziptasticapi.com/%@",zipcode];




        url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


        NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

        NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
        [connection start];



        NSError *noconnection;
        NSString *htmlpage = [NSString stringWithContentsOfURL:[NSURL URLWithString: url]                                                                        encoding:NSASCIIStringEncoding
                                                         error:&noconnection];
        //NSLog(htmlpage);

        if ([htmlpage rangeOfString:@"error"].location == NSNotFound) {
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"{" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"}" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@":" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"\"" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"country" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"city" withString:@""];
            htmlpage = [htmlpage stringByReplacingOccurrencesOfString:@"state" withString:@""];
            NSLog(htmlpage);


        } else {

            zipcodetextfield.text = @"";

            UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Error"
                                                              message:@"We were unable to locate this zipcode. Please try again"
                                                             delegate:nil
                                                    cancelButtonTitle:@"OK"
                                                    otherButtonTitles:nil];
            message.translatesAutoresizingMaskIntoConstraints = NO;

            [message show];

        }

    }else{
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Error"
                                                          message:@"Please Enter A ZipCode"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
        message.translatesAutoresizingMaskIntoConstraints = NO;

        [message show];

    }
}
-(IBAction)exitkeyboard:(id)sender{
    [zipcodetextfield resignFirstResponder];

}

@end

我绝对会在这里结束,所以任何帮助都会非常感激。

由于

0 个答案:

没有答案