如何更改或扩展 NSCollectionView 的委托?
NSCollectionView
有一个委托,它应该符合 NSCollectionViewDelegate
。
- (id < NSCollectionViewDelegate >)delegate
我有一个新协议,它扩展了 NSCollectionViewDelegate
。
@protocol extendedProtocol <NSCollectionViewDelegate>
现在,在我的 CollectionViewItem 的控制器类中,我尝试以这种方式调用委托的方法:
if (
[self collectionView]
&& [[self collectionView] delegate] &&
[[[self collectionView] delegate] conformsToProtocol:@protocol(extendedProtocol)]
)
{
BOOL flag = [[[self collectionView] delegate] doSomeWork:@"abc"];
}
我不断收到“找不到实例方法'doSomeWork:'”的警告。
我尝试这样做,
id <extendedProtocol> dg = [[self collectionView] delegate];
BOOL flag = [dg doSomeWork:@"abc"];
但随后我收到警告,“不兼容的指针类型用“id”类型的表达式初始化“id”。
更改 NSCollectionView 委托协议的正确方法是什么?
NSCollectionView
has a delegate which should conform to NSCollectionViewDelegate
.
- (id < NSCollectionViewDelegate >)delegate
I have a new protocol, which extends NSCollectionViewDelegate
.
@protocol extendedProtocol <NSCollectionViewDelegate>
Now, in my CollectionViewItem's controller class, I try to call the delegate's method in this way:
if (
[self collectionView]
&& [[self collectionView] delegate] &&
[[[self collectionView] delegate] conformsToProtocol:@protocol(extendedProtocol)]
)
{
BOOL flag = [[[self collectionView] delegate] doSomeWork:@"abc"];
}
I keep getting warning that "Instance Method 'doSomeWork:' not found".
I tried doing
id <extendedProtocol> dg = [[self collectionView] delegate];
BOOL flag = [dg doSomeWork:@"abc"];
But then I get warning, "Incompatible pointer types initializing 'id' with an expression of type 'id'.
What is the correct way of changing the protocol of NSCollectionView delegate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要一个演员阵容。要么像这样:
或者在你的第二个例子中:
You need a cast. Either like this:
Or in your second example: