这是我的Obj代码:
NSMutableArray *staffNamesArray = [[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:@"staffNamesArray"] mutableCopy];
NSInteger indexSelected = [oStaffPickerView selectedRowInComponent:0];
[staffNamesArray replaceObjectAtIndex:indexSelected withObject:textField.text];
[[NSUbiquitousKeyValueStore defaultStore] setArray: staffNamesArray forKey:@"staffNamesArray"]; // save it to the cloud
[[NSUbiquitousKeyValueStore defaultStore] synchronize];IndexSelected为0;textfield.text = @"Kellie“。
由于某种原因,staffNamesArray从来没有被设置过。为什么?
发布于 2015-01-06 02:48:53
最有可能的问题是这一行:
NSMutableArray *staffNamesArray = [[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:@"staffNamesArray"] mutableCopy];如果没有数据,这将导致staffNamesArray成为nil。您需要检查这一点,并根据需要创建一个数组:
NSMutableArray *staffNamesArray = [[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:@"staffNamesArray"] mutableCopy];
if (!staffNamesArray) {
staffNamesArray = [NSMutableArray array];
}
// and the rest of your codehttps://stackoverflow.com/questions/27789726
复制相似问题