处理应用程序代理并切换视图 [英] Handling app delegates and switching between views

查看:71
本文介绍了处理应用程序代理并切换视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在收到关于传递 * const _strong 以输入 id 的语义问题的警告,似乎无法解决它,无论我改变什么。

I'm getting a warning about a semantic issue pertaining to passing a *const _strong to type id and cannot seem to fix it no matter what I change.

我目前有两个意见,并写了这段代码。在iPadSpeckViewController.m中,这里是应该在视图之间切换的方法:

I have two views at the moment, and have written this code. In iPadSpeckViewController.m, here is the method that should switch between views:

-(IBAction) touchProducts {
    ProductsViewController *controller = [[ProductsViewController alloc]
            initWithNibName:@"Products" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    controller.delegate = self;
    [self presentModalViewController:controller animated:YES];
}

而对于ProductsViewController.h:

And for ProductsViewController.h:

@interface ProductsViewController : UIViewController {
    id<ProductsViewControllerDelegate> delegate;
}
@property(nonatomic, retain)
    IBOutlet id<ProductsViewControllerDelegate> delegate;

ProductsViewController.m包含:

ProductsViewController.m contains:

@synthesize delegate;

但是视图不会切换...想法?

But the views do not switch... Thoughts?

编辑:
这是确切的警告,就像在controller.delegate = self一样。在iPadSpeckViewController.m中:

Here is the exact warning, as it appears on the line "controller.delegate = self;" in iPadSpeckViewController.m:

/Developer/iPadSpeckApp/iPadSpeckApp/iPadSpeckAppViewController.m:17:27:{17:27-17:31}: warning: passing 'iPadSpeckAppViewController *const __strong' to parameter of incompatible type 'id<ProductsViewControllerDelegate>' [3]


推荐答案

这个警告是奇怪的措辞,但实际上只是告诉你自己的类(不管该类是什么)不符合ProductsViewControllerDelegate协议。要摆脱警告,你有两个选择:

This warning is oddly worded, but it is actually just a way of telling you that the class of self (whatever that class is) fails to conform to the ProductsViewControllerDelegate protocol. To get rid of the warning, you have two choices:


  • 声明自己的类(不管类是什么),在其 @interface 语句,以符合协议ProductsViewControllerDelegate。或者...

  • Declare the class of self (whatever that class is), in its @interface statement, to conform to the protocol ProductsViewControllerDelegate. Or...

通过更改此项来抑制警告:

Suppress the warning by changing this:

controller.delegate = self;

到:

controller.delegate = (id)self;


委托属性键入为 id< ProductsViewControllerDelegate> 。但自己不是。在ARC下,您必须明确表示,直到类型正式同意。 (我相信,这样ARC可以绝对确定它有足够的信息来做出正确的内存管理决策。)

The delegate property is typed as id<ProductsViewControllerDelegate>. But self is not. Under ARC you must make the cast explicit, so that the types formally agree. (I believe this is so that ARC can make absolutely certain it has sufficient information to make correct memory management decisions.)

这篇关于处理应用程序代理并切换视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆