Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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
Iphone 比较objective-c中的两个字符串会导致应用程序退出_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 比较objective-c中的两个字符串会导致应用程序退出

Iphone 比较objective-c中的两个字符串会导致应用程序退出,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我试图用“isEqualToString”来比较两个字符串,但我似乎无法让它工作。一旦开始运行if语句,它就会退出应用程序。我很确定这些弦实际上是相等的,尽管我尽了最大的努力,我还是没有办法。任何帮助都将不胜感激 -(void)createTextfields{ name = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 140, 25)]; name.borderStyle = UITextBorderStyleRou

我试图用“isEqualToString”来比较两个字符串,但我似乎无法让它工作。一旦开始运行if语句,它就会退出应用程序。我很确定这些弦实际上是相等的,尽管我尽了最大的努力,我还是没有办法。任何帮助都将不胜感激

-(void)createTextfields{
    name = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 140, 25)];
    name.borderStyle = UITextBorderStyleRoundedRect;
    name.textColor = [UIColor blackColor];
    name.placeholder = @"Password";
    name.textAlignment = UITextAlignmentCenter;
    [self addSubview:name];

    entry = [[UITextField alloc] initWithFrame:CGRectMake(170, 0, 140, 25)];
    entry.borderStyle = UITextBorderStyleLine;
    entry.textColor = [UIColor blueColor];
    entry.textAlignment = UITextAlignmentCenter;
    [self addSubview:entry];
}

-(void)createSubmitButton{
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    submit.titleLabel.textAlignment = UITextAlignmentCenter;
    [submit setTitle:@"Submit" forState:UIControlStateNormal];
    submit.frame = CGRectMake(90, 50, 60, 30);
    [submit addTarget:self action:@selector(runSubmit) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:submit];


    UIButton *savePass = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    savePass.titleLabel.textAlignment = UITextAlignmentCenter;
    [savePass setTitle:@"Save" forState:UIControlStateNormal];
    savePass.frame = CGRectMake(20, 50, 60, 30);
    [savePass addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:savePass];
}

-(void)save{

    tempPass = name.text;
    name.text = @"";
    entry.text = tempPass;

}

-(void)runSubmit{

//  password = name.text;

    if ([tempPass isEqualToString:name.text]) {
        //[viewController displayAlertFromViewControl];
    }else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct" message:@"Alert" delegate: self cancelButtonTitle:@"Close" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }


}

可能您的一个字符串(非常确定它是tempPass)被自动删除了

在哪里声明了
tempPass
?如果您使用以下菜单项运行程序:运行->使用性能工具运行->僵尸,它是否可能没有被保留足够长的时间以在
中引用
然后仪器将为您完成追踪问题的所有艰苦工作。它将向您显示哪个对象是提前发布的,以及在哪里分配的


可能是临时通行证。一旦确定是否存在这种情况,最好将tempPass设置为具有复制属性的属性,然后使用self.tempPass=name.text,而不仅仅是tempPass=name.text。

僵尸项目菜单变灰,您知道如何使其可选择吗。您还可以给我一个带有复制属性的属性的代码示例。