如何限制FBFriendPicker中的朋友选择?

时间:2013-05-30 12:17:31

标签: ios facebook facebook-ios-sdk

我在我的应用中使用Facebook SDK 我想在Facebook FriendPicker中将朋友选择限制为指定的数字? 我正在尝试这段代码: -

 - (void)friendPickerViewControllerSelectionDidChange:
      (FBFriendPickerViewController *)friendPicker
    {
        if ([friendPicker.selection count] >= 3) {
            UIAlertView *alertView = 
                [[UIAlertView alloc] initWithTitle:@""
                                           message:@"Max number of friends selected."
                                          delegate:self cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
            [alertView show];
        }
    }

    - (void)alertView:(UIAlertView *)alertView 
       clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }

我收到了alert,但我无法理解FBFriendpickercontroller 知道为什么吗?

1 个答案:

答案 0 :(得分:2)

得到了!!!!!!! 解决方案比我想象的简单。 您friendPickerController是一个tableView,因此我们可以将userInteractionEnabled属性设置为NO

- (void)friendPickerViewControllerSelectionDidChange:
(FBFriendPickerViewController *)friendPicker
{
    if ([friendPicker.selection count] <=3)
    {
        self.friendPickerController.tableView.userInteractionEnabled=YES;
    }

if ([friendPicker.selection count] >=3)
{
    UIAlertView *maxFriendsAlert =
    [[UIAlertView alloc] initWithTitle:@"Max number of friends selected."
                               message:@"no more friends can be selected,"
                              delegate:self cancelButtonTitle:@"OK"
                     otherButtonTitles:@"Buy more friends",nil];
    [maxFriendsAlert show];
    maxFriendsAlert.tag=1;

// disable friends selection
        self.friendPickerController.tableView.userInteractionEnabled=NO;
    }