0

私は FBFriendPickerViewController を促す ViewController を持っています。選択時に、選択を含む 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 は選択されたフレンドの正しい数を返すようですが、numberOfRowsInSection-log は 0 を返します。

どうしてこれなの?

前もって感謝します!

4

2 に答える 2

2

ここでの問題はセッターにあります:

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

プロパティをサポートするインスタンス変数の値を実際に設定することはないことに気付くでしょう。この場合、デフォルトはです_selectedParticipants。したがって、修正するには、セッターに次の行を追加するだけです。

_selectedParticipants = selectedParticipants;

そして、あなたは行ってもいいはずです。

于 2013-03-16T14:37:03.377 に答える
0

コードからこの関数を削除します

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

既に init メソッドで selectedParticipants を設定しています

于 2013-03-16T14:35:38.400 に答える