Xcode plist在模拟器上保存但在iPhone上没有

时间:2012-08-25 18:41:53

标签: iphone xcode ios-simulator

我正在编写一个程序,将锻炼保存到沙盒中的plist。按下按钮后,它会保存,并且名称在文本视图中。在保存之后,它将锻炼添加到tableview中。实现在模拟器中运行良好,但在实际的iPhone上却没有。有什么建议? (另外,这是我的第一篇文章,所以请耐心等待。谢谢)

- (NSString *)dataFilePath {
    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFileName];
}

- (IBAction)buttonPressed:(id)sender {

    if ([saveNameTextView.text length] == 0) {  //name is not added to the textview for saving
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops =(" message:@"You need to enter a name for the workout" delegate:self cancelButtonTitle:@"OK, I'll add a name" otherButtonTitles: nil];
        [alert show];
    }else { //name is added for saving in the textview
        NSString *filePath = [self dataFilePath];
        NSMutableDictionary *savedWorkout = [[NSMutableDictionary alloc]initWithContentsOfFile:filePath];

        if ([savedWorkout objectForKey:saveNameTextView.text]) { //if the name already exists, alert the user
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops =(" message:@"Name is already taken, please choose another" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }else{  //save the workout
            [savedWorkout setObject:self.saveDetails forKey:saveNameTextView.text];
            [savedWorkout writeToFile:[self dataFilePath] atomically:YES];
            NSString* saveConfirm = [[NSString alloc] initWithFormat:@"%@ has been saved",saveNameTextView.text];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Save Complete" message:saveConfirm delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }//end if
    }//end if
}

0 个答案:

没有答案
相关问题