[英]Pushing a UIViewController from a UIView
我需要將UIView
推送到UINavigation controller
。 我正在這樣做
[self.view addSubview:showContactFlow];
而在UIView的點擊一個按鈕,我需要在推動另一個的UIViewController UIView
。 我無法從UIView
訪問self.navigationcontroller
如何執行此操作?
編輯:
我已經將UIView
設置為我要插入的新UIViewController
的視圖,即前面提到的UIViewController
。 現在,我想知道如何在UIViewController
處理UIView
按鈕事件,在該視圖中設置該事件。
將UINavigationController
ivar添加到UIView
並將其分配給主視圖控制器。 然后,您應該能夠從UIView
訪問它。
編輯:
您的UIView子類:
// CustomView.h
@interface CustomView: UIView {
// ...
// your variables
// ...
UINavigationController *navController;
}
@property (nonatomic, assign) UINavigationController *navController; // assign, because this class is not the owner of the controller
// custom methods
@end
// CustomView.m
@implementation Customview
// synthesize other properties
@synthesize navController;
// implementation of custom methods
// don't release the navigation controller in the dealloc method, your class doesn't own it
@end
然后在[self.view addSubview:showContactFlow];
之前[self.view addSubview:showContactFlow];
行只需添加[showContactFlow setNavController:[self navigationController]];
然后,您應該能夠從UIView
訪問層次結構的導航控制器,並使用它來推送其他UIViewController
。
您應該嘗試使用MVC方法。 因此,您的控制器可以訪問所有這些內容,並且可以繼續推送和彈出視圖,因此視圖不需要對控制器了解太多。
否則,對於這種情況,您可以使用委托快速解決。 所以:
showContactFlow.delegate = self;
[self.view addSubview:showContactFlow];
因此,稍后在UIView
,您可以說:
[self.delegate addSubview:self];
這是可行的,但它不一定是您應該使用的最佳方法。
點擊按鈕后,您可以顯示一個視圖控制器,例如
-(void)buttonFunction{
ThirdVC *third= [[ThirdVC alloc]initWithNibNme];......
[self presentViewController:third animated:NO];
}
使用Core動畫,您可以在ThirdVC的viewWillAppear:方法中編寫代碼,使NavigationController的pushviewController像動畫一樣。
您在showContactFlow視圖或ViewController的視圖中在哪里添加UIButton?
關於modalViewControllers問題,正確的方法是
[self presentModalViewController:viewController animated:YES];
向上的標准動畫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.