你真的會用storyboard開發嗎?

在通常的佈局中,咱們先使用一個plist文件,作爲tabbarVC的的4個選項 pilist文件以下 在此輸入圖片描述 而後建立多個Storyboard,以及Storyboard關聯的文件, 而後刪除啓動的一些sb界面,讓界面啓動時候從AppDelegate中啓動, 在AppDelegate中寫下以下代碼git

<!-- lang: cpp -->
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

self.window  = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
//b不要在主方法中寫碎代碼
[self setUI];
[self.window makeKeyAndVisible];
return YES;

}github

-(void)setUI{app

UITabBarController *uiTabBar = [[UITabBarController alloc] init];

NSURL *url = [[NSBundle mainBundle] URLForResource:@"MainUI" withExtension:@"plist"];
NSArray *arr = [NSArray arrayWithContentsOfURL:url];

for (NSDictionary *dic in arr) {
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:dic[@"vcName"] bundle:nil];
    UIViewController *uiVC = sb.instantiateInitialViewController;
    uiVC.title = dic[@"title"];
    uiVC.tabBarItem.image = [UIImage imageNamed:dic[@"icon"]];
    uiVC.tabBarItem.badgeValue = dic[@"badgeNumber"];
    
    [uiTabBar addChildViewController:uiVC];
}

self.window.rootViewController = uiTabBar;

}ide

而後就能看到以下功能了,佈局

效果以下 在此輸入圖片描述ui

那在SB文件中的按鈕點擊跳轉到其餘SB文件中怎麼處理呢?以下代碼:url

<!-- lang: cpp -->
  • (IBAction)clickBtn:(id)sender { UIStoryboard *sb = [UIStoryboard storyboardWithName:@"hhh" bundle:nil]; UIViewController *vc = sb.instantiateInitialViewController; [self.navigationController pushViewController:vc animated:YES]; }

固然我講的確定不是很清晰,下面你看下個人源代碼吧!嘻嘻,但願對你有用!code

下面是我在gitthub上詳細地址:https://github.com/pyawkk/SB-.git圖片

相關文章
相關標籤/搜索