Get Selected index of UITableView

前端 未结 5 1997
忘了有多久
忘了有多久 2020-12-04 16:09

I want to have selected index for UITableView. I have written following code:

NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
         


        
相关标签:
5条回答
  • 2020-12-04 16:34
    NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
    
    0 讨论(0)
  • 2020-12-04 16:52

    Swift 4.2

    let selectedIndexPath = tableView.indexPathForSelectedRow
    

    which is an optional return value.

    0 讨论(0)
  • Use this code

    CGPoint location =[sender locationInView:self.tableView];
    NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:location];
    UITableViewCell *swipedCell  = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
    NSIndexPath *indexPath = [self.tableView indexPathForCell:swipedCell];
    
    0 讨论(0)
  • 2020-12-04 16:56

    Get current selected row. May be helpful if you have only one section.

    - (NSUInteger)currentSellectedRowIndex
    {
        NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
        if (selectedIndexPath) {
            return selectedIndexPath.row;
        }
        else {
            return NSNotFound;
        }
    }
    
    0 讨论(0)
  • 2020-12-04 16:56

    In didSelectRowAtIndexPath, set an interface declared NSIndexPath as the indexpath returned. Then you can scroll to that variable. If you need help, comment and I can give some sample code.

    0 讨论(0)
提交回复
热议问题