我有一个 ViewController 提示 FBFriendPickerViewController 在其中我在选择时返回一个包含选择的 NSArray。现在我想使用这个选择信息提示并显示一个新的 ViewController。我是 Objective C 的新手,但我想解决方案很简单。这是我的建议:
ViewController2.h
- (id)initWithStyle:(UITableViewStyle)style andSelection:(NSArray *)selection;
@property (strong, nonatomic) NSArray *selectedParticipants;
视图控制器2.m
- (id)initWithStyle:(UITableViewStyle)style andSelection:(NSArray *)selection {
self = [super initWithStyle:style];
if (self) {
self.title = NSLocalizedString(@"Split Bill", nil);
self.tableView.backgroundColor = [UIColor wuffBackgroundColor];
self.selectedParticipants = selection;
}
return self;
}
- (void)setSelectedParticipants:(NSArray *)selectedParticipants {
NSLog(@"setSelectedParticipants (%d)", [selectedParticipants count]);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%d rowsInSection", [self.selectedParticipants count]);
return [self.selectedParticipants count];
}
ViewController1.m
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 2) {
[[self friendPickerController] presentModallyFromViewController:self animated:YES handler:^(FBViewController *sender, BOOL donePressed) {
if (donePressed) {
ViewController2 *vc = [[ViewController2 alloc] initWithStyle:UITableViewStyleGrouped
andSelection:[self.friendPickerController selection]];
[self.navigationController pushViewController:vc animated:YES];
}
//[[self friendPickerController] clearSelection];
}
];
}
}
然而,似乎第一个 setSelectedParticipants-log 返回了正确数量的选定朋友,但 numberOfRowsInSection-log 返回 0。
为什么是这样?
提前致谢!