经过设置,启动显示不了tabbar control,请指教

iOS 码拜 9年前 (2015-05-08) 781次浏览 0个评论
 

新建一个 window-base appliction

双击 mainwindow.xib
从library 拖一个tabbar control到mainwindow.xib窗口
保存
返回xcode
在主类.h文件
添加

#import <UIKit/UIKit.h>

@interface tabbarTestAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
     UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end

主类.m 

@synthesize tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    
    // Override point for customization after application launch.
     [self.window addSubview:tabBarController.view];//这里应该是启动显示tabbar control吧?
    [self.window makeKeyAndVisible];
    
    return YES;
}

[tabBarController release];

为什么启动程序没有显示新建的tabbar control,而是显示window?

可以正常显示啊,直接在IB下面把tabbar control拖到window下,做为window的子视图就行了。
25分
需要在IB里手动关联tabcontroller到appdelegate里定义的tabcontroller变量.
引用 2 楼 comeback2009 的回复:

需要在IB里手动关联tabcontroller到appdelegate里定义的tabcontroller变量.

为什么要这么关联呢?其中的原理是什么?

1楼都说了

        是做为它的    子视图

10分
IB 这个东西很容易把人搞糊涂了,而且一旦出问题也不好查找。
设计的想法是好的:UI设计与编码设计分离

只是太不好用了,更多还是喜欢用代码敲,而不是用IB布局。

5分
关联类似MS系统下的事件注册。
直接按Control建将App  Delegate拖拽到tabbarController就能完成手动关联吗?但是我这样关联以后为什么还是不能现实tabbarController

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明经过设置,启动显示不了tabbar control,请指教
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!