我设置了tableViewController
来显示有关managedObjectContext
中对象的数据。我没有从编译器中收到任何错误,程序运行正常,直到我单击单元格中的UIButton进行筛选为止。
我正在尝试选择与managedObjectContext
中的对象关联的纬度和经度值,并将这些值传递给另一个VC。
这是我的prepareForSegue
:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"directionsSegue"]) {
// Set destination view controller
DirectionsViewController *destinationVC = segue.destinationViewController;
// Pick out the "thing" you want to send to destinationVC
CGPoint point = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
NSLog(@"NSIndexPath *indexPath's index is %@", indexPath);
// Set the "thing" on the destinationVC
PointOfInterest *poi = [self.fetchedResultsController objectAtIndexPath:indexPath];
destinationVC.destinationLatitude = poi.latitude;
destinationVC.destinationLongitude = poi.longitude;
}
}
这是我的控制台日志:
2015-03-15 12:01:18.449 BlocSpot[11680:832245] savedPOI managedObjectContext is <NSManagedObjectContext: 0x7fad650b1e60>
2015-03-15 12:20:12.719 BlocSpot[11680:832245] -[SavedPOITableViewController convertPoint:toView:]: unrecognized selector sent to instance 0x7fad62c6f640
2015-03-15 12:20:12.728 BlocSpot[11680:832245] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SavedPOITableViewController convertPoint:toView:]: unrecognized selector sent to instance 0x7fad62c6f640'
*** First throw call stack:
(
0 CoreFoundation 0x000000010955eb95 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108e3dbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010956606d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001094bc1bc ___forwarding___ + 988
4 CoreFoundation 0x00000001094bbd58 _CF_forwarding_prep_0 + 120
5 BlocSpot 0x000000010836ae54 -[SavedPOITableViewController prepareForSegue:sender:] + 276
6 UIKit 0x000000010a0d471c -[UIStoryboardSegueTemplate _perform:] + 151
7 BlocSpot 0x000000010836ad1b -[SavedPOITableViewController directionButton:] + 91
更新资料
添加以下代码以设置我的
CGPoint
后: UIView *view = [(SavedPOITableViewController *)sender view];
它走得更远,但仍然崩溃。这是日志:
2015-03-15 12:39:50.073 BlocSpot[11915:852339] savedPOI managedObjectContext is <NSManagedObjectContext: 0x7ffaac51d850>
2015-03-15 12:39:51.661 BlocSpot[11915:852339] NSIndexPath *indexPath's index is <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}
2015-03-15 12:39:51.662 BlocSpot[11915:852339] -[UIButton view]: unrecognized selector sent to instance 0x7ffaac5eb330
2015-03-15 12:39:51.665 BlocSpot[11915:852339] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton view]: unrecognized selector sent to instance 0x7ffaac5eb330'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d2dbb95 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010cbbabb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010d2e306d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010d2391bc ___forwarding___ + 988
4 CoreFoundation 0x000000010d238d58 _CF_forwarding_prep_0 + 120
5 BlocSpot 0x000000010c0e7dcf -[SavedPOITableViewController prepareForSegue:sender:] + 207
6 UIKit 0x000000010de5171c -[UIStoryboardSegueTemplate _perform:] + 151
最佳答案
在这条线
CGPoint point = [sender convertPoint:CGPointZero toView:self.tableView];
您是在
convertPoint:toView:
上调用SavedPOITableViewController
的方法,但这不是视图控制器的方法,而是视图的方法。尝试以下方法:CGPoint point = [self.view convertPoint:CGPointZero toView:self.tableView];