我做了什么:
UIView
(s),并启用了分页。UIView
的子类中,当我们按下那个按钮时会调用它。答案 0 :(得分:1)
您需要为自定义UIView类实现协议方法。
例如;
#import <UIKit/UIKit.h>
@protocol YourCustomViewDelegate <NSObject>
- (void)buttonTapped;
@end
@interface YourCustomView : UIView
@property (nonatomic, strong) id< YourCustomViewDelegate > delegate;
@end
你可以在.m文件中调用buttonTapped委托方法。
- (void)myCustomClassButtonTapped:(id)sender
{
[self.delegate buttonTapped];
}
正确的工作;
修改强>
我将尝试说明非常简单的协议用法,希望它能帮到你。
#import "MyViewController.h"
#import "YourCustomView.h"
@interface MyViewController ()<YourCustomViewDelegate> // this part is important
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
YourCustomView *customView = // initialize your custom view, I suppose that you already did it
customView.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)buttonTapped
{
YOUR_VIEW_CONTROLLER_CLASS *viewCon =[storyboard instantiateViewControllerWithIdentifier:@"mainVC"]; //mainVC is just a example and u will have to replace it with your viewController storyboard id
//Pushing VC
[self.navigationController pushViewController:viewCon animated:YES];
}
答案 1 :(得分:0)
看看这个
YourViewController *obj=[[YourViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:obj];
[[[UIApplication sharedApplication]keyWindow].rootViewController presentViewController:nav animated:YES completion:NULL];
答案 2 :(得分:0)
试试这个
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* initialView = [storyboard instantiateInitialViewController];
答案 3 :(得分:0)
首先,您需要将Storyboard Id设置为ViewController,即“mainVC”。然后你可以使用下面的代码推送/展示它: -
YOUR_VIEW_CONTROLLER_CLASS *viewCon =[storyboard instantiateViewControllerWithIdentifier:@"mainVC"]; //mainVC is just a example and u will have to replace it with your viewController storyboard id
//Pushing VC
[self.navigationController pushViewController:viewCon animated:YES];
//OR presenting VC
[self presentViewController:viewCon animated:YES completion:nil];
如果您希望在下面启动另一个故事板,
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; //Change MainStoryboard with your storyboard id
答案 4 :(得分:0)
希望这会有所帮助
我认为你的问题的方式是
- &gt;右键你的内部你在UIView
类,里面有一个按钮,你可以通过点击它来推送或呈现一个ViewController和offcourse,你不能推动或呈现你的视图控制器。所以
你可以先做一个简单的事情,首先在action方法中创建一个ref(前向声明),或者你可以创建一个你的UIView现在存在的ViewController类的全新对象,然后调用一个函数(存在于你的中) ViewController)喜欢
//在你的uiview calss中运行
- (void)btnaction
{
[_objCSInformationViewController pushViewController];
}
//在视图控制器中运行
-(void)pushViewController
{
yourViewController *objViewController = [[yourViewController alloc]initWithNibName:@"yourViewController" bundle:nil];
[strong.navigationController pushViewController:objViewController animated:YES];
}