Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 协议不响应选择器_Ios_Objective C Protocol - Fatal编程技术网

Ios 协议不响应选择器

Ios 协议不响应选择器,ios,objective-c-protocol,Ios,Objective C Protocol,我对Objective-C协议有问题 我定义了协议: @protocol PlayerProfileSectionProReviewDelegate <NSObject> - (void)didReceivedPlayerProfileSectionProReviewData; @end @interface PlayerProfileSectionProReviewModel : PlayerProfileSectionModel @property (weak) id &

我对Objective-C协议有问题

我定义了协议:

@protocol PlayerProfileSectionProReviewDelegate <NSObject>

- (void)didReceivedPlayerProfileSectionProReviewData;

@end

@interface PlayerProfileSectionProReviewModel : PlayerProfileSectionModel

@property (weak) id <PlayerProfileSectionProReviewDelegate> playerProfileSectionProReviewDelegate;

@end
在视图控制器中,我添加了
PlayerProfileSectionProReviewDelegate
并重写了
didReceivedPlayerProfileSectionProReviewData
方法:

@interface PlayerProfileSectionProReviewViewController : PlayerProfileSectionViewController <UITableViewDelegate, UITableViewDataSource, PlayerProfileSectionProReviewDelegate>

@end
@interface PlayerProfileSectionProReviewViewController:PlayerProfileSectionViewController
@结束

#pragma标记
-(无效)未收到LayerProfileSectionProReviewData
{
[self.playerProReviewTableView重新加载数据];
}

为什么我的协议不响应选择器?

PlayerProfileSectionProReviewViewController
类实现中的某个地方,需要设置相应的
PlayerProfileSectionProReviewModel
对象的委托,如下所示:

myModel.playerProfileSectionProReviewDelegate = self;
如果执行此操作,则当
myModel
到达代理调用时,视图控制器将收到该调用

顺便说一下,您可以简化这些行:

if ([self.playerProfileSectionProReviewDelegate respondsToSelector:@selector(didReceivedPlayerProfileSectionProReviewData)])
{
    [self.playerProfileSectionProReviewDelegate didReceivedPlayerProfileSectionProReviewData];
}
与:


此时,如果委托为
nil
,则不会发送任何消息,也不会出现任何运行时错误

是否
\u播放机配置文件部分proreviewdelegate
?另外,您可能希望将
playerProfileSectionProReviewDelegate
定义为
weak
属性。是的,
\u playerProfileSectionProReviewDelegate
nil
!如何处理?您已经定义了一个
playerProfileSectionProReviewDelegate
属性,但这只是一个属性。这就像一个变量的名字——鞋盒。你没有给它任何价值。除非你让某个对象成为这个委托,否则那里没有人——鞋盒是空的(零)。。。但是,如何初始化它呢<代码>\u playerProfileSectionProReviewDelegate=[[playerProfileSectionProReviewDelegate alloc]init]?你会看到的,非常感谢!这是一个愚蠢的错误,花了我这么长时间!
myModel.playerProfileSectionProReviewDelegate = self;
if ([self.playerProfileSectionProReviewDelegate respondsToSelector:@selector(didReceivedPlayerProfileSectionProReviewData)])
{
    [self.playerProfileSectionProReviewDelegate didReceivedPlayerProfileSectionProReviewData];
}
[self.playerProfileSectionProReviewDelegate didReceivedPlayerProfileSectionProReviewData];