gpt4 book ai didi

ios - 无法识别的选择器发送到 ViewController 的实例

转载 作者:行者123 更新时间:2023-11-29 00:38:31 25 4
gpt4 key购买 nike

我在Appdelegate.m中创建了一个方法

- (AppDelegate *)service;

现在在 ViewController 中我包含了应用委托(delegate):

#import "AppDelegate.h"

在 ViewController.h 中,我创建了带有“弱”引用的属性:

@property (nonatomic, weak) GDataServiceGooglePhotos *service;

在实现文件ViewController.m中:

_service = [(AppDelegate *)[[UIApplication sharedApplication] delegate] service];

但它显示错误,

-[AppDelegate service]: unrecognized selector sent to instance 0x7a284bc0
2016-10-14 14:21:34.216 PicassaClient[2474:134418] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate service]: unrecognized selector sent to instance 0x7a284bc0'

我哪里错了?

最佳答案

有几件事需要注意,

首先,你正在调用一个方法,但你没有定义,这就是它崩溃的原因。

像下面这样改变,

Appdelegate.h

添加这个

- (GDataServiceGooglePhotos *)service; //it returns the type `GDataServiceGooglePhotos`

Appdelegate.m

- (GDataServiceGooglePhotos *)service 
{
//your code


//finally
return myGDataServiceGooglePhotos; // it is the instance of type GDataServiceGooglePhotos
}

在 ViewController.h 中,与您所做的相同

@property (nonatomic, weak) GDataServiceGooglePhotos *service;

在 ViewController.m 中:

_service = [(AppDelegate *)[[UIApplication sharedApplication] delegate] service]; //hear u are calling the method named "service" which is returning  an instance of type "GDataServiceGooglePhotos"

关于ios - 无法识别的选择器发送到 ViewController 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40043181/

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