每个Navigation再包含各自的界面控制器的结构,代码如下: //创建两个自己的界面控制器 ViewControllerOne *one = [[ViewControllerOne alloc]initWithNibName :@"ViewControllerOne" bundle:nil]; ViewControllerTwo *two= [[ViewControllerTwo alloc]initWithNibName 不加这一句将会有一段状态栏高度的空白区域 此外,导航栏的标题可以在各个页面中自行设置,比如在viewDidload方法中,如下: self.title = @"标题" 要设置各个界面的tab样式,可以在initWithNibName
RedViewController.h" @interface RedViewController () @end @implementation RedViewController - (id)initWithNibName :(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil //创建tabbar所管理的子控制器,每个子控制器都带有一个导航 RedViewController *redVC = [[RedViewController alloc]initWithNibName initWithRootViewController:redVC]; GreenViewController *greenVC = [[GreenViewController alloc]initWithNibName ]initWithRootViewController:greenVC]; BlueViewController *blueVC = [[BlueViewController alloc]initWithNibName
self = [super init]; NSLog(@"%s", __func__); return self; } -(instancetype)initWithNibName :(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:( } @end 结论总结 如果控制器是直接通过代码创建出来的,并且调用方法为[[YFViewController alloc]init]创建VC的生命周期为: -[YFViewController initWithNibName viewDidAppear:] 如果创建控制器时勾选了XIB,那么调用方法为[[YFViewController alloc]init]创建VC时的生命周期为: -[YFViewController initWithNibName
deckController; //.m文件 //中间视图 CenterViewController *centerView = [[CenterViewController alloc] initWithNibName CenterViewController" bundle:nil]; //左、右视图 LeftViewController *leftView = [[LeftViewController alloc] initWithNibName :@"LeftViewController" bundle:nil]; RightViewController *rightView = [[RightViewController alloc] initWithNibName self action:@selector(toLeft)]; //左、右视图 LeftViewController *leftView = [[LeftViewController alloc] initWithNibName :@"LeftViewController" bundle:nil]; RightViewController *rightView = [[RightViewController alloc] initWithNibName
NSBundle bundleForClass:EmViewController.class]; UIViewController *vc = [[EmViewController alloc] initWithNibName 也就是:库名称.framework/xxxx.nib才是bundle能够搜索到的资源 UIViewController *vc = [[EmViewController alloc] initWithNibName ] forCellReuseIdentifier:@"TableViewCell"]; 那么可能你会有疑问为啥此时的EmViewController加载xib需要initWithNibName
中, #import "MainViewController.h" #import "MainView.h" @implementation MainViewController - (id)initWithNibName :(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil
Paste_Image.png 3.通过Xib 要是用控制器alloc】 initWithNibName:bundle:】 bundle传nil默认就是从[NSBundle mainBundle] ? Paste_Image.png // 只有控制器的init方法底层会调用initWithNibName:bundle: ? Paste_Image.png // 只要通过initWithNibName:bundle:初始化控制器,并且nibName为nil,就会执行以下几步。
dic; @property (nonatomic, retain) NSArray *titles; @end @implementation RootViewController - (id)initWithNibName :(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil
btnClicked:(id)sender { // Swift文件 ChildViewController *vc = [[ChildViewController alloc] initWithNibName
代码如下: FileOverviewViewController *fileOverviewViewController = [[FileOverviewViewController alloc] initWithNibName
第一种加载方式,传入指定的xib(如CustomViewController) CustomViewController *custom = [[CustomViewController alloc]initWithNibName CustomViewController" bundle:nil]; 第二种加载方式,不指定xib CustomViewController *custom = [[CustomViewController alloc]initWithNibName
YES]; Assuming you have a xib file you want to do: UIViewController *vc = [[UIViewController alloc] initWithNibName
[ibTextLabel setText:nil]; DetailViewController *_curDetail = [[DetailViewController alloc] initWithNibName
UIViewController 的生命周期 // 非storyBoard(xib或非xib)都走这个方法 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { NSLog(@"%s", __FUNCTION__); if (self = [super initWithNibName [super didReceiveMemoryWarning]; } // 视图被销毁 - (void)dealloc { NSLog(@"%s", __FUNCTION__); } 分析 initWithNibName initWithCoder: 如果使用StoryBoard进行视图管理,程序不会直接初始化一个UIViewController,StoryBoard会自动初始化或在segue被触发时自动初始化,因此方法initWithNibName
pragma mark - 添加子控制器 - (void)addSubControllers { _childViewController = [[InfoViewController alloc] initWithNibName
RenwuMyViewController; 根据xib实例化控制器 RenwuMyViewController * renwuMy Controller = [[RenwuMyViewController alloc] initWithNibName
// Use RootViewController manage CCEAGLView viewController = [[RootViewController alloc] initWithNibName
init]; //创建一个要被推入的视图控制器,然后添加此视图控制器到导航栏并予以显示 UIViewController *aView = [[UIViewController alloc] initWithNibName 代码一是由initWithNibName:方法来加载具体的某个视图控制器并自定义该控制器中TabBarItem样式外观等。 C代码 - (id)init { if(self = [super initWithNibName:@"MyViewController" bundle:nil]) { self.title
OneViewController : XLFormViewController @end @implementation OneViewController - (instancetype)initWithNibName :(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil
return self; } @end 下面是UIViewController的初始化: #pragma mark - Designated Initializer - (instancetype)initWithNibName 里设置的数据,在初始化后会调用awakeFromNib 方法,我们需要把额外初始化动作写在这里 UIView的DI是initWithFrame: UIViewController的DI是init和 initWithNibName