2012-01-02 31 views
8

Tôi muốn chọn ô trong bảngView. Nó hoạt động đúng cách bằng cách sử dụng mã này, nhưng khi được chọn theo chương trình, nó sẽ không kích hoạt sự kiện didSelectRowAtIndexPath. Làm thế nào tôi có thể kích hoạt nó?didSelectRowAtIndexPath sự kiện không được kích hoạt khi chọn hàng lập trình

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.mainTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 

Trả lời

22

Nó đang làm việc như tài liệu:

Gọi phương pháp này không gây ra các đại biểu để nhận được một thông tableView:willSelectRowAtIndexPath: hoặc tableView:didSelectRowAtIndexPath:, và cũng không nó sẽ gửi thông báo UITableViewSelectionDidChangeNotification để quan sát viên.

Gọi nó cho mình sau khi chọn di động của bạn:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 

[self tableView:self.mainTable willSelectRowAtIndexPath:indexPath]; 
[self.mainTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
[self tableView:self.mainTable didSelectRowAtIndexPath:indexPath]; 
+0

làm việc, nhờ sự giúp đỡ – Jaume

+0

Đối với du khách trong tương lai: Đây là một lời giải thích rất nhiều lý do tại sao điều này không làm việc, nhưng tôi tin rằng đây là một nhiều giải pháp toàn diện: http://stackoverflow.com/questions/2305781/iphone-didselectrowatindexpath-not-invoked – kbpontius

Các vấn đề liên quan