2011-08-18 86 views
0

我用下面的代码以编程方式选择的tableview细胞当以编程方式进行选择时,TableView是否生成didSelectRowAtIndexPath事件?

- (void) selectTableCell{ 
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:0]; 
[tableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom]; 

NSIndexPath *ip1 = [NSIndexPath indexPathForRow:1 inSection:0]; 
[tableView selectRowAtIndexPath:ip1 animated:YES scrollPosition:UITableViewScrollPositionBottom];} 

出于测试目的,我想做到这一点。我如何生成didselect事件?

感谢, Lalith

回答

6

文档明确告诉你会发生什么:

调用此方法不会导致委托接收tableView:willSelectRowAtIndexPath:tableView:didSelectRowAtIndexPath:消息,也不会向观察者发送UITableViewSelectionDidChangeNotification通知。

您可以尝试自己调用这些方法,但不保证能够复制原始功能。

要测试您的UI,您应该尽可能使用基于工具的UI自动化测试。

5

我想这应该工作:

if ([tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) { 
    [tableView.delegate tableView:tableView didSelectRowAtIndexPath:ip]; 
} 
+0

nope ..我的意思是它只是运行该方法..事件不会被解雇 – Lalith

+0

如果你正确med200建议在你的selectRowAtIndexPath调用下面它应该调用didSelectRowAtIndexPath委托方法 – arniotaki

相关问题