0

在我的 ios 应用程序中,我想知道哪个 indexPathUITableViewCell选中

基本上,我试图将朋友选择限制为 3 个朋友,因为如果选择计数大于 3,我禁用了 tableview 的用户交互。现在,如果所选行等于选中的行,我想再次启用它,以便用户可以替换通过取消选中当前选中标记的行中的任何一个来与另一个朋友成为朋友。我试过这个:-

 #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;
    }

}

问题是我不知道已经选中的 uitableviewcell 的索引路径

4

1 回答 1

0

编辑:啊哈,现在我明白你的问题了。

也许这会起作用:

- (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;
        }
    }
}
于 2013-06-10T07:27:26.333 回答