Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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
Ios 无法在另一个数组中添加数组的对象_Ios_Objective C_Iphone_Arrays - Fatal编程技术网

Ios 无法在另一个数组中添加数组的对象

Ios 无法在另一个数组中添加数组的对象,ios,objective-c,iphone,arrays,Ios,Objective C,Iphone,Arrays,当用户脱机时,我试图显示所选单元格复选标记,但数组没有添加其他数组对象,请帮助我 1.appDelegate.SelectedArray保存选定单元格 2.buildingObject.SelectedString保存选中的单元格索引 //首先,我要从数组中删除所有对象 [appDelegate.SelectedArray removeAllObjects] //然后我在arraye.g3,2,7中添加字符串值 //现在在appDelegate.SelectedArray中添加tempArray

当用户脱机时,我试图显示所选单元格复选标记,但数组没有添加其他数组对象,请帮助我

1.appDelegate.SelectedArray保存选定单元格 2.buildingObject.SelectedString保存选中的单元格索引

//首先,我要从数组中删除所有对象

[appDelegate.SelectedArray removeAllObjects]

//然后我在arraye.g3,2,7中添加字符串值

//现在在appDelegate.SelectedArray中添加tempArray数组对象

//现在显示appDelegate.SelectedDarray中添加对象的计数


我希望您没有忘记分配appDelegate。请选择eDarray。

你好,伙计,请尝试此操作

NSArray *tempArray = [buildingObject.selectedIDString componentsSeparatedByString:@","];

[appDelegate setSelectedIDArray:[tempArray mutableCopy]];

如果它不起作用,那么可能有一个数组是空的。请检查使用它,如果您使用的是非arc,它将修复
appDelegate.SelectedArray=[tempArray retain]

所谓脱机,是指应用程序已终止,如果您未将数组保存在NSUserDefaults中,则该数组已为零。然后你应该初始化它。如果不是这种情况,appDelegate可能存在另一个问题:

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSString *vals = @"1,2,3,4,5,6,7,8";
    NSMutableArray *tempArray = [[vals componentsSeparatedByString:@","] mutableCopy];
    if (!appDelegate.SelectedIDArray) {
        appDelegate.SelectedIDArray = [NSMutableArray new];
    }
    else
    { 
        [appDelegate.SelectedIDArray removeAllObjects];
    }
    [appDelegate.SelectedIDArray addObjectsFromArray:tempArray];
    NSLog(@"%@", appDelegate.SelectedIDArray);

我已经获取了与您的代码类似的示例测试用例:

NSString *str1 = @"1,2,3,4,5,6,7,8,9";
NSMutableArray *tempArray = (NSMutableArray*)[str1 componentsSeparatedByString:@","];
NSMutableArray *arr = [NSMutableArray array];
[arr addObjectsFromArray:tempArray];
NSLog(@"%@",arr);
这对我来说很好。确保appDelegate.SelectedArray为NSMutableArray。或者,如果您想要新的数组,只需使用

appDelegate.SelectedArray=[NSMutableArray数组WithArray:tempArr]


希望这有帮助。

是appDelegate.SelectedDarray==nil吗?是appDelegate.SelectedDarray==nil吗?是的,我正在删除所有对象。您分配数组了吗?请检查我的答案buddyi had alloc in appdelegatetempArray count可以,但SelectedDarray count仍然为零
NSArray *tempArray = [buildingObject.selectedIDString componentsSeparatedByString:@","];

[appDelegate setSelectedIDArray:[tempArray mutableCopy]];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSString *vals = @"1,2,3,4,5,6,7,8";
    NSMutableArray *tempArray = [[vals componentsSeparatedByString:@","] mutableCopy];
    if (!appDelegate.SelectedIDArray) {
        appDelegate.SelectedIDArray = [NSMutableArray new];
    }
    else
    { 
        [appDelegate.SelectedIDArray removeAllObjects];
    }
    [appDelegate.SelectedIDArray addObjectsFromArray:tempArray];
    NSLog(@"%@", appDelegate.SelectedIDArray);
NSString *str1 = @"1,2,3,4,5,6,7,8,9";
NSMutableArray *tempArray = (NSMutableArray*)[str1 componentsSeparatedByString:@","];
NSMutableArray *arr = [NSMutableArray array];
[arr addObjectsFromArray:tempArray];
NSLog(@"%@",arr);