我在尝试索引用户名的数组中重新分配数据时遇到问题。我能够将我的原始数组分成单独的对象,但无法将值发送到我稍后需要引用的新数组。我的行中 userNames 的值和计数self.userNamesArray = 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];
}
}
}