简体   繁体   中英

UIAlertview error: Unable to simultaneously satisfy constraints

This question has been asked many times, but I have tried all of the options, and none of them seem to work. In my ios app, whenever I try to make an alert view, this happens:

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

I don't know what to do. When I click ok, I get this error: (This is the entire error)

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

My code is:

@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

I am at absolute wits end here, so any help would be greatly appreciated.

Thanks

message.translatesAutoresizingMaskIntoConstraints = NO;

不要为UIAlertView设置此项-警报视图及其私有管理器将决定其布局如何工作。

尝试使用delegate:self而不是nil并在您的.h文件中添加UIAlertViewDelegate ,使其看起来像这样:

@interface AJSettingsViewController : UIViewController <UIAlertViewDelegate>

Try to use UIAlertController:

UIAlertController *myAlertController = [UIAlertController
                                      alertControllerWithTitle:@"Title"
                                      message:@"Message"
                                      preferredStyle:UIAlertControllerStyleAlert];

with buttons:

UIAlertAction *myCancelAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction *action)
                               {
                                   NSLog(@"Cancel action");
                                   [self someGreatActionWithIndex:0];
                               }];

UIAlertAction *myOkAction = [UIAlertAction
                           actionWithTitle:NSLocalizedString(@"OK", @"OK")
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action)
                           {
                               NSLog(@"OK action");
                               [self someGreatActionWithIndex:1];
                           }];

[myAlertController addAction:myCancelAction];
[myAlertController addAction:myOkAction];

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM