0

in my ios app, i want to know indexPath for UITableViewCell which is checkmarked?

basically i am trying to limit friend selection to 3 friends for that i disabled userinteraction for tableview if selection count is greater than 3. now i want to enable it again if selected row is equal to row which is checkmarked, so that user can replace the friend with another friend by unchecking any one of the current checkmarked row. i tried this :-

 #pragma mark Limiting number of friends selected to 3
- (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;

#pragma mark disable friends selection
        self.friendPickerController.tableView.userInteractionEnabled=NO;
    }

    //enable friend selection if selected row is equal to checkmarked row i.e. enable selection for previously checkmarked row
    NSIndexPath *oldindexPath1=[self.friendPickerController.selection objectAtIndex:0];
    NSIndexPath *oldindexPath2=[self.friendPickerController.selection objectAtIndex:1];
    NSIndexPath *oldindexPath3=[self.friendPickerController.selection objectAtIndex:2];

    if (self.friendPickerController.tableView.indexPathForSelectedRow==oldindexPath1||self.friendPickerController.tableView.indexPathForSelectedRow==oldindexPath2||self.friendPickerController.tableView.indexPathForSelectedRow==oldindexPath3)
    {
        self.friendPickerController.tableView.userInteractionEnabled=YES;
    }

}

problem is i cant know indexpath for uitableviewcell which is already checkmarked

Ashish P
  • 1,463
  • 1
  • 20
  • 29
  • Have you tried NSArray *selectedFriends = [self.friendPickerController.tableView indexPathsForSelectedRows]; – Peter Warbo Jun 08 '13 at 15:11
  • yes @PeterWarbo it returns indexPath for currently selected row as it says in its name and not the index path for checkMarked row but thnx for your response – Ashish P Jun 09 '13 at 15:56
  • How about iterating through all the UITableViewCells of the tableView and check if the accessoryType property is UITableViewCellAccessoryCheckmark ? – Peter Warbo Jun 09 '13 at 16:55

1 Answers1

0

EDIT: Aha, now I understand your issue.

Maybe this will work:

- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker {

    UITableView *friendPickerTable = friendPicker.tableView;
    NSArray *indexPathsForSelectedRows = friendPickerTable.indexPathsForSelectedRows;

    NSIndexPath *indexPathForSelectedRow = friendPickerTable.indexPathForSelectedRow;

    if([indexPathsForSelectedRows containsObject:indexPathForSelectedRow]) {

        // Checked friend has previously been checked
        friendPickerTable.userInteractionEnabled = YES;

    } else {

        // New checkmark
        NSUInteger checkCount = indexPathsForSelectedRows.count;

        if (checkCount > 3) {

            // Alert the user
            UIAlertView *alert = ...
            friendPickerTable.userInteractionEnabled = NO;

        } else {

            friendPickerTable.userInteractionEnabled = YES;
        }
    }
}
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • no it doesnt work. it disables selection after 1st row is checked – Ashish P Jun 10 '13 at 11:31
  • What's the output? cell is `nil` or the checked cells don't have the `accessoryType` set to `UITableViewCellAccessoryCheckmark` ? – Peter Warbo Jun 10 '13 at 12:46
  • it displays cell is checked and cell is not checked if i display the log inside if-else.so i guess cells have the accessory type checkmark. if i enable user interaction if cell is checked by :- self.friendPickerController.tableView.userInteractionEnabled=YES; and disable if cell is not checked it disables selection after first row is checked. – Ashish P Jun 10 '13 at 13:32
  • have you tried implimenting it? this is really the basic functionality for facebook friendpicker and it would be great if we could limit number of selectable friends. – Ashish P Jun 10 '13 at 13:39
  • I think I understand your issue now, try with my updated code to see if that works for you. – Peter Warbo Jun 10 '13 at 15:12
  • no it doesnt disable user interaction ! but thnx for trying. hopefully we could solve this! – Ashish P Jun 11 '13 at 06:46