前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS-如何创建一个新的App基础框架

iOS-如何创建一个新的App基础框架

原创
作者头像
Wilbur-L
修改2021-09-24 18:00:42
1.2K0
修改2021-09-24 18:00:42
举报
文章被收录于专栏:iOS底层原理iOS底层原理

一·项目创建

Create
Create

二·创建自己的专属BasicViewController

删掉自带的ViewController,并且分别创建Main ViewController View Model

基类
基类

三·实现Screen的Delegate方法

代码语言:javascript
复制
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
 [self initUI];
}

四·创建基础框架

属性:

代码语言:javascript
复制
@interface SceneDelegate ()<UITabBarControllerDelegate>
@property (nonatomic, strong)PersonalViewController *personalVC; //我的
@property (nonatomic, strong)SuperMainViewController *homePageMainVC; //主页
@property (nonatomic, strong)UITabBarController *tab; //tabbar栏
@property (nonatomic, strong)UINavigationController *nav;
@end

由于我想实现一个底部tabbar栏切换不覆盖的视图所以是以一个NavigationViewController作为RootWindow

代码语言:javascript
复制
- (void)initUI {
 [self tab]; //懒加载
 [self nav]; //懒加载
 self.nav = [[UINavigationController alloc]initWithRootViewController:self.tab]; //根视图
 [self.tab setViewControllers:@[self.homePageMainVC,self.personalVC]]; //底部Tabbar栏个数
 self.tab.delegate = self; 
 self.window.rootViewController = self.nav; //根VC
 [self.window makeKeyAndVisible]; //可视化
}

懒加载

代码语言:javascript
复制
- (UITabBarController *)tab {
 if (!_tab) {
 _tab = [[UITabBarController alloc]init];
 }
 return _tab;
}

- (UINavigationController *)nav {
 if (!_nav) {
 _nav = [[UINavigationController alloc]init];
 }
 return _nav;
}

五·MVC

在上一步中分别有SuperMainViewController,PersonalViewController 这里拿PersonalViewControllerVC来做例子

注意新建的VC必须继承自自己创建的BasicViewController 因为这样以来就可以管理并控制整个App的生命周期

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import "BasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface MainViewController : BasicViewController
@end

代码语言:javascript
复制
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) FirstView *firstView;
@end

根据MVC的概念可以知道Model层负责数据传递,但是没有说明的一个重要的地方就是Model在哪里传递!

这里拿tableView做例子

因为我遵循了UITableViewDataSource,UITableViewDelegate

所以必须实现其中一个方法

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id"];
 if (!cell) {
 cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"id"];
 }
 YourModel *model = _dataArr[indexPath.row];
 cell.model = model;
 cell.textLabel.text = @"来教室里的会计法";
 cell.detailTextLabel.text = @"sldkfj";
 return cell;
}

关于MVC更具体的说明可以参考我的另外一篇文章iOS-NSArray与Model模型

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一·项目创建
  • 二·创建自己的专属BasicViewController
  • 三·实现Screen的Delegate方法
  • 四·创建基础框架
    • 懒加载
    • 五·MVC
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档