Ios 通过引用传递UIViewController或在另一个处理程序类中获取自我控制
我已经创建了一个单独的类MyUtil,用于处理一些基本操作,如导航左右按钮及其事件。LeftButton(UIBarButton left)已处理,但显示了right,但未处理 请给我建议另一条路 MyUtil.hIos 通过引用传递UIViewController或在另一个处理程序类中获取自我控制,ios,uinavigationcontroller,uinavigationitem,Ios,Uinavigationcontroller,Uinavigationitem,我已经创建了一个单独的类MyUtil,用于处理一些基本操作,如导航左右按钮及其事件。LeftButton(UIBarButton left)已处理,但显示了right,但未处理 请给我建议另一条路 MyUtil.h #import <Foundation/Foundation.h> @interface @interface MyUtil : NSObject @property(strong,nonatomic) UIViewControll
#import <Foundation/Foundation.h>
@interface
@interface MyUtil : NSObject
@property(strong,nonatomic) UIViewController *uiv;
-(void)NavAndBackBtn:(UIViewController *)context;// it is running awesome.
-(void)NavAndForwardBtn:(UIViewController *)context :(NSString *)vc_name;//it displays right button but don't know how to add pushViewController to it in this class.
//context is self of calling ViewController and vc_name is the name of ViewController which i want to push
@end
@结束
我已经试了两天了,但没有找到一个方法让自己在另一节课上通过引用。有人说不可能通过引用传递,但它可以做任何你想做的事情。我将self发送到MyUtil.m类,它显示right和left UINavigationItem.leftButton和righButton
MyUtil中的左按钮
[leftbutton addTarget:context.navigationController action:@selector(popViewControllerAnimated:)forControlEvents:UIControlEventTouchUpInside]; //it is doing absolutely what i wanted..
现在右键打开(按ViewController)我做了
[rightbutton addTarget:context.navigationController操作:@selector(pushViewController:animated:)forControlEvents:UIControlEventTouchUpInside]
//如何传递UIViewController以打开。上述函数如何知道打开什么
我尝试了多种方法来解决这个问题
在选择器中传递多个参数的第一种方法强>
myMethode:(NSArray*)参数
问题1
是否可以将self作为&self发送。在另一个类中得到它。我在MyUtil.h中尝试了它。我也使用**双指针,但它没有传递
问题2
在我的例子中,是否可以将多个参数设置为UIViewController和NSString,或者两者都设置为UIViewController
问题3
是否有方法将UIViewController发送或附加到给定语句
问题4
我已经创建了一个@属性(强,非原子)UIViewController*vc代码>
当我将调用ViewController的self分配给vc时。它没有像我预期的那样工作。有没有办法让另一个ViewController的self在该类的属性中被处理和捕获
[button addTarget:context.navigationController action:@selector(pushViewController:animated:) forControlEvents:UIControlEventTouchUpInside];
//我如何告诉此函数推送哪个ViewController,因为函数中有两个UIViewController
注意
我在另一个名为MyUtil的班级工作。主要问题是我无法从MyUtils中的函数调用[self.navigationController pushViewController:anyVC]
。也许我错了,但为什么不在UIViewController上创建一个类别来处理您想要做的事情呢?MyUtil所做的对我来说就像一个类别,在这种情况下,您可以访问UIViewController的self
[button addTarget:context.navigationController action:@selector(pushViewController:animated:) forControlEvents:UIControlEventTouchUpInside];