IOS 7如何使用UITableView的scrollToRowAtIndexPath

我是新来的IOS 7,我做了一个testing应用程序,当我想要使用scrollToRowAtIndexPath检测到左侧滑动。 滑动被检测到,但我正在努力与“自我”的定义。 我得到错误没有可见@interface为'SimpleTableViewController'

- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer { NSLog(@"%u = %d", recognizer.direction,recognizer.state); // jump to section 0 row 20 when leftswipe is dectected NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:20 inSection:0]; [self.tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; } 

我可以发送完整的源代码,如果你想或者你可以在这里下载:

www.auditext.com/xintax/SimpleTable.zip

使用self.tableView给消息Property'tableView'找不到'SimpleTableViewController'types的对象 –

它现在工作,我已经把这行添加到我的viewcontroller.h:@属性(强,非primefaces)IBOutlet UITableView * myview;

NSIndexPath * loc = [NSIndexPath indexPathForRow:row inSection:section];

[self.myview scrollToRowAtIndexPath:loc atScrollPosition:UITableViewScrollPositionBottom animated:YES]; `

你需要指向UItableView

 [self.tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; 

在这里输入图像说明

你只需要调用self.tableView而不是self。 自引用TableViewController和self.tableView到它的tableView。

为什么你得到这个错误,因为scrollToRowAtIndexPath是一个UITableView方法请参考这个 。

而且你正在调用与self相同的方法,这表明你的类名SimpleTableViewController 。 所以你得到这个错误No visible @interface for 'SimpleTableViewController' 。 用self.tableView调用这个方法,而不是使用self

注意:-

1)声明你的头文件中的属性SimpleTableViewController @property(nonatomic,strong)UITableView *tableView

2)如果您使用的Xcode版本高于4,则不需要明确包含合成。