gpt4 book ai didi

iphone - Obj-C 全局使用 NSArray

转载 作者:行者123 更新时间:2023-11-28 22:37:43 24 4
gpt4 key购买 nike

我有一个 ViewController 提示 FBFriendPickerViewController,在其中我在选择时返回一个包含选择的 NSArray。现在我想使用此选择信息提示并显示一个新的 ViewController。我是 Objective C 的新手,但我想解决方案非常简单。这是我的建议:

ViewController2.h

- (id)initWithStyle:(UITableViewStyle)style andSelection:(NSArray *)selection;
@property (strong, nonatomic) NSArray *selectedParticipants;

ViewController2.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 似乎返回了正确数量的选定 friend ,但是 numberOfRowsInSection-log 返回了 0。

这是为什么?

提前致谢!

最佳答案

这里的问题出在你的 setter 上:

- (void)setSelectedParticipants:(NSArray *)selectedParticipants {
NSLog(@"setSelectedParticipants (%d)", [selectedParticipants count]);
}

您会注意到您实际上从未为支持该属性的实例变量设置值,在这种情况下,默认值为 _selectedParticipants。因此,要修复,只需将以下行添加到您的 setter 中:

_selectedParticipants = selectedParticipants;

你应该可以开始了。

关于iphone - Obj-C 全局使用 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15450491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com