iOS*_*Dev 104 iphone objective-c uitableview nsindexpath ios
我想选择索引UITableView.我写了以下代码:
NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
[tableView scrollToRowAtIndexPath:index
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
Run Code Online (Sandbox Code Playgroud)
这总是适用于第一项.我想要选择索引indexPathForRow.
请帮忙.谢谢.
小智 216
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
Run Code Online (Sandbox Code Playgroud)
获取当前选定的行.如果您只有一个部分,可能会有所帮助.
- (NSUInteger)currentSellectedRowIndex
{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
if (selectedIndexPath) {
return selectedIndexPath.row;
}
else {
return NSNotFound;
}
}
Run Code Online (Sandbox Code Playgroud)
使用此代码
CGPoint location =[sender locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
NSIndexPath *indexPath = [self.tableView indexPathForCell:swipedCell];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81133 次 |
| 最近记录: |