2013-05-30 36 views
2

我在我的應用程序中使用Facebook SDK 我試圖將朋友選擇限制在Facebook FriendPicker中的指定號碼? 我想這個代碼: -如何限制朋友在FBFriendPicker中的選擇?

- (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,但我不能dissmiss的FBFriendpickercontroller 任何想法,爲什麼?

+1

自己是FBFriendPickerViewController對象嗎? – satheeshwaran

+0

沒有它的視圖控制器對象 –

+0

得到這是問題。它應該是self.FBFriendspickerViewController,而不是自己 –

回答

2

明白了!!!!!!!解決方案比我想像的更簡單。 you 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; 
    } 
+0

然後用戶不能取消選擇一個朋友回限制下。我試圖想出一個解決方案來只禁用未選中的單元格 –