Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c 保存UITextfield信息时出现问题_Objective C_Sdk_Nsmutablearray - Fatal编程技术网

Objective c 保存UITextfield信息时出现问题

Objective c 保存UITextfield信息时出现问题,objective-c,sdk,nsmutablearray,Objective C,Sdk,Nsmutablearray,当我尝试使用NSUserdefaults保存UITextFields信息时出现问题(崩溃)。我知道这与我正在使用的数组有关。代码如下: - (IBAction)generateNumbers { // release and remove everyting from the name array // [nameArray release]; nameArray = nil; // reinitilize the name array name

当我尝试使用NSUserdefaults保存UITextFields信息时出现问题(崩溃)。我知道这与我正在使用的数组有关。代码如下:

- (IBAction)generateNumbers 
{
    // release and remove everyting from the name array
    //    [nameArray release];
    nameArray = nil;

    // reinitilize the name array
    nameArray = [[NSMutableArray alloc] init];

    // Loop through the textfields to get the names into the nameArray
    for (int textFieldCount = 0; textFieldCount<[textFieldArray count]; textFieldCount++) {
        [nameArray addObject:[[textFieldArray objectAtIndex:textFieldCount] text]];
    }

    // Randomly sort the names in the array
    [nameArray sortUsingFunction:randomSort context:nil];

    // Add the random names back into the text fields
    for (int textFieldCount = 0; textFieldCount<[textFieldArray count]; textFieldCount++) {
        [[textFieldArray objectAtIndex:textFieldCount] setText:[nameArray     objectAtIndex:textFieldCount]];
    }
}

      int randomSort(id obj1, id obj2, void *context ) {
         // returns random number -1 0 1
       return (arc4random()%3 - 1);
} 

保存数据时不要忘记使用方法:

[[NSUserDefaults standardUserDefaults] synchronize];

请修改代码。它甚至不会编译什么样的崩溃错误?text1在哪里声明?您使用的是ARC吗?在我添加NSUserdefaults以保存信息之前,一切正常。以下是我收到的错误消息:**由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'***-[\uu NSArrayM insertObject:atIndex:]:对象不能为零
 - (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
        [[NSUserDefaults standardUserDefaults] setObject:tex1.text forKey:@"storedTextValue48"];
[[NSUserDefaults standardUserDefaults] synchronize];