![](/img/trans.png)
[英]iOS UITableView scrollToRowAtIndexPath behave incorrectly
[英]IOS 7 how to use UITableView scrollToRowAtIndexPath
我是IOS 7的新手,我制作了一个测试应用程序,在检测到向左滑动时,我想使用scrollToRowAtIndexPath。 可以检测到滑动,但是我在“自我”定义方面苦苦挣扎。 我收到错误消息“ SimpleTableViewController”没有可见的@interface
- (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会在类型为'SimpleTableViewController'的对象上提供消息属性'tableView'-
现在可以正常工作了,我已将以下行添加到viewcontroller.h中:`@property(强,非原子)IBOutlet UITableView * myview;
NSIndexPath * loc = [NSIndexPath indexPathForRow:row inSection:section];
[self.myview scrollToRowAtIndexPath:loc atScrollPosition:UITableViewScrollPositionBottom animation:YES]; `
您需要指向UItableView
[self.tableView scrollToRowAtIndexPath:newIndexPath
atScrollPosition:UITableViewScrollPositionTop
animated:NO];
您只需要调用self.tableView而不是self。 self引用TableViewController,self.tableView引用它的tableView。
为什么会出现此错误,因为scrollToRowAtIndexPath
是UITableView
方法。请参阅this 。
而且,您正在使用self
调用相同的方法,该方法指示您的类名称SimpleTableViewController
。 因此,您将收到此错误No visible @interface for 'SimpleTableViewController'
。 只需使用self.tableView
调用此方法,而不是使用self
。
注意:-
1)在头文件SimpleTableViewController
@property(nonatomic,strong)UITableView *tableView
声明属性
2)如果您使用的Xcode版本高于4,则无需显式包括合成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.