gpt4 book ai didi

ios - 在 Core Data 应用程序中进行 segueing 时 prepareForSegue 崩溃

转载 作者:行者123 更新时间:2023-11-28 21:48:54 25 4
gpt4 key购买 nike

我设置了一个 tableViewController 来显示有关 managedObjectContext 中对象的数据。我没有从编译器中收到任何错误,程序运行正常,直到我单击单元格中的 UIButton 进行 segue。

我正在尝试挑选出与 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];

您正在 SavedPOITableViewController 上调用 convertPoint:toView:,但这不是您的 View Controller 的方法,它是一个 View 的方法。试试这个:

CGPoint point = [self.view convertPoint:CGPointZero toView:self.tableView];

关于ios - 在 Core Data 应用程序中进行 segueing 时 prepareForSegue 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29063091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com