在我尝试索引用户名的数组中,我无法重新分配数据。我能够将我的原始数组分离为单个对象,但无法将该值发送给我需要稍后参考的新数组。我的self.userNamesArray = userNames;
行中的userNames的值和计数是正确的。但之后,当我登录self.userNamesArray,我得到(null)。任何提示,因为我不完全确定我是干杯!访问可变数组时遇到问题
.H
@property (nonatomic, copy) NSMutableArray *userNamesArray;
.M
- (void)viewWillAppear:(BOOL)animated {
self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
else {
self.friends = objects;
NSArray *users = [self.friends valueForKey:@"username"];
NSLog(@"username:%@", users);
//Create an array of name wrappers and pass to the root view controller.
NSMutableArray *userNames = [[NSMutableArray alloc] initWithCapacity:[self.friends count]];
for (NSString *user in users) {
componentsSeparatedByCharactersInSet:charSet];
NSArray *nameComponents = [user componentsSeparatedByString:@" "];
UserNameWrapper *userNameWrapper = [[UserNameWrapper alloc] initWithUserName:nil nameComponents:nameComponents];
[userNames addObject:userNameWrapper];
}
self.userNamesArray = userNames;
NSLog(@"userNamesArray:%@",self.userNamesArray);
[self.tableView reloadData];
}
这里就是我需要引用self.userNamesArray在那里再次,它是作曲了零代码。
- (void)setUserNamesArray:(NSMutableArray *)newDataArray {
if (newDataArray != self.userNamesArray) {
self.userNamesArray = [newDataArray mutableCopy];
if (self.userNamesArray == nil) {
self.sectionsArray = nil;
NSLog(@"user names empty");
}
else {
[self configureSections];
}
}
}
请添加语言标签。 –