Doesn't TableView generate didSelectRowAtIndexPath event when selection is made programmatically?
I have used the following code to programmatically select tableview cells
- (void) selectT开发者_Python百科ableCell{
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];}
For testing purposes I wanted to do this. How do I generate the didselect event?
The documentation explicitly tells you what happens:
Calling this method does not cause the delegate to receive a
tableView:willSelectRowAtIndexPath:
ortableView:didSelectRowAtIndexPath:
message, nor will it sendUITableViewSelectionDidChangeNotification
notifications to observers.
You could try to call these methods yourself but you are not guaranteed that will replicate the original functionality.
To test your UI, you should probably use the Instruments-based UI Automation Testing if possible.
I guess this should work:
if ([tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[tableView.delegate tableView:tableView didSelectRowAtIndexPath:ip];
}
精彩评论