004:搭建常规项目框架「Window、TabBar、NavigationController、ViewController」

news2024/10/7 14:24:31

常见App页面结构分析:

单页面展示:

  • 列表页面的展示「UITableView」。
  • 滚动页面的展示「UIScrollow」。

多页面展示:

  • 通过底部标签栏「TabBar」。
  • 通过Push栈的方式进行页面的切换。

UITabBarController:

介绍:通过底部对应标签点击来管理多个ViewController之间的切换「一般4-5个可选选项」。

图示:


UITabBar:「UITabBarItem提供内容」

介绍:展示对应标签、管理对应的ViewController以及响应对应的事件。

图示:


 NavigationController

介绍:通过出栈入栈「Push/Pop」的方式管理页面之间的跳转。

图示:

​​​​​


UINavigationBar:「UIBarButtonItem提供内容」

介绍:展示设置导航的内容包括标题、背景色、按钮等。

图示:


UIWindow:

介绍:提供App展示的基础窗口,继承UIView。

图示:


搭建App:

Next 1:删除系统自动生成的Main.storyboard文件。Application Scene Manifest\Main storyboard file base name。

图示:

 Next 2.1:创建Window以及第一种架构模式。

 代码演示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    JKNewVc *newVc = [[JKNewVc alloc] init];
    newVc.tabBarItem.image = [UIImage imageNamed:@"page"];
    newVc.tabBarItem.selectedImage = [UIImage imageNamed:@"page_selected"];
    newVc.tabBarItem.title = @"新闻";
    newVc.navigationItem.title = @"新闻";
    UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:newVc];
    
    JKVideoVc *videoVc = [[JKVideoVc alloc] init];
    videoVc.tabBarItem.image = [UIImage imageNamed:@"video"];
    videoVc.tabBarItem.selectedImage = [UIImage imageNamed:@"video_selected"];
    videoVc.tabBarItem.title = @"视频";
    videoVc.navigationItem.title = @"视频";
    UINavigationController *videoNav = [[UINavigationController alloc] initWithRootViewController:videoVc];

    JKRecommendVc *recomendVc = [[JKRecommendVc alloc] init];
    recomendVc.tabBarItem.image = [UIImage imageNamed:@"like"];
    recomendVc.tabBarItem.selectedImage = [UIImage imageNamed:@"like_selected"];
    recomendVc.tabBarItem.title = @"推荐";
    recomendVc.navigationItem.title = @"推荐";
    UINavigationController *recomendNav = [[UINavigationController alloc] initWithRootViewController:recomendVc];
    
    JKMainVc *mainVc = [[JKMainVc alloc] init];
    mainVc.tabBarItem.image = [UIImage imageNamed:@"home"];
    mainVc.tabBarItem.selectedImage = [UIImage imageNamed:@"home_selected"];
    mainVc.tabBarItem.title = @"我的";
    mainVc.navigationItem.title = @"我的";
    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVc];
    
    UITabBarController *tabbarVc = [[UITabBarController alloc] init];
    tabbarVc.viewControllers = @[newNav,videoNav,recomendNav,mainNav];
    self.window.rootViewController = tabbarVc;
    [self.window makeKeyAndVisible];
    
    // Override point for customization after application launch.
    return YES;
}

 Next 2.2:创建Window以及第二种架构模式。

代码演示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    JKNewVc *newVc = [[JKNewVc alloc] init];
    newVc.tabBarItem.image = [UIImage imageNamed:@"page"];
    newVc.tabBarItem.selectedImage = [UIImage imageNamed:@"page_selected"];
    newVc.tabBarItem.title = @"新闻";
    newVc.navigationItem.title = @"新闻";
    
    JKVideoVc *videoVc = [[JKVideoVc alloc] init];
    videoVc.tabBarItem.image = [UIImage imageNamed:@"video"];
    videoVc.tabBarItem.selectedImage = [UIImage imageNamed:@"video_selected"];
    videoVc.tabBarItem.title = @"视频";
    videoVc.navigationItem.title = @"视频";

    JKRecommendVc *recomendVc = [[JKRecommendVc alloc] init];
    recomendVc.tabBarItem.image = [UIImage imageNamed:@"like"];
    recomendVc.tabBarItem.selectedImage = [UIImage imageNamed:@"like_selected"];
    recomendVc.tabBarItem.title = @"推荐";
    recomendVc.navigationItem.title = @"推荐";
    
    JKMainVc *mainVc = [[JKMainVc alloc] init];
    mainVc.tabBarItem.image = [UIImage imageNamed:@"home"];
    mainVc.tabBarItem.selectedImage = [UIImage imageNamed:@"home_selected"];
    mainVc.tabBarItem.title = @"我的";
    mainVc.navigationItem.title = @"我的";
    
    UITabBarController *tabbarVc = [[UITabBarController alloc] init];
    tabbarVc.viewControllers = @[newVc,videoVc,recomendVc,mainVc];
    
    UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:tabbarVc];
    
    self.window.rootViewController = newNav;
    [self.window makeKeyAndVisible];
    
    // Override point for customization after application launch.
    return YES;
}

Delegate:

介绍:给某对象提供一个代理以控制对该对象的访问。这时,访问对象不适合或者不能直接引用目标对象,代理对象作为访问对象和目标对象之间的中介。

 自定义代理:「常见系统代理」:AppDelegate、UITabBarControllerDelegate、UITableViewDelegate等

 Next 1:委托方:声明协议、声明协议对象、对应的事件告诉代理要做什么。

/*.h文件*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class Person;
@protocol PersonDelegate <NSObject>
//必须实现
@required
- (void)eating;
- (void)runPerson:(Person *)per;
//可选实现
@optional
- (void)playing;

@end


@interface Person : NSObject

@property (nonatomic,assign) id<PersonDelegate>delegate;

- (void)printLogType:(int)type;

@end

NS_ASSUME_NONNULL_END

/*.m文件*/
#import "Person.h"

@implementation Person

- (void)printLogType:(int)type{
    if (type == 0){
        if ([self.delegate respondsToSelector:@selector(eating)]){
            [self.delegate eating];
        }
    }else if (type == 1){
        if ([self.delegate respondsToSelector:@selector(runPerson:)]){
            [self.delegate runPerson:self];
        }
    }else if (type == 2){
        if ([self.delegate respondsToSelector:@selector(playing)]){
            [self.delegate playing];
        }
    }
}
@end

 Next 2:代理方:成为委托方的代理、遵守委托方的协议、完成委托方需要的方法。


#import "JKNewVc.h"
#import "Person.h"
@interface JKNewVc ()<PersonDelegate>

@end

@implementation JKNewVc

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Person *per = [Person new];
    per.delegate = self;
    [per printLogType:1];
    
    // Do any additional setup after loading the view.
}

#pragma mark - PersonDelegate

-(void)eating{
    代理eating 回调
}

-(void)runPerson:(Person *)per{
     代理runPerson 回调
}

-(void)playing{
     代理playing 回调
}

@end

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/83903.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

打响跨域/中央计算「攻坚」战,这些头部企业已经抢先布局

从域控架构到中央集成式架构&#xff0c;跨域融合已经加速到来&#xff0c;从单一域控制器&#xff0c;到多域融合中央计算&#xff0c;市场门槛进一步抬升&#xff0c;市场也进入新一轮「攻坚」阶段。 高工智能汽车研究院发布《2023-2025年智能网联产业趋势报告》显示&#x…

Flink Checkpoint 问题排查实用指南

在 Flink 中,状态可靠性保证由 Checkpoint 支持,当作业出现 failover 的情况下, Flink 会从最近成功的 Checkpoint 恢复。在实际情况中,我们可能会遇到 Checkpoint 失败,或者 Checkpoint 慢的情况,本文会统一聊一聊 Flink 中 Checkpoint 异常的情况(包括失败和慢),以及…

【单片机】串口通信/LED点阵

目录 一、串口介绍 1、双向串口通信 2、电平标准 3、常用通信协议 4、时序图 二、串口收发数据&#xff08;模式1&#xff09; 1、串行控制&#xff08;模式选择&#xff09;寄存器SCON&#xff08;可位寻址&#xff09; 2、串行口数据缓冲寄存器SBUF 3、电源控制&…

引擎入门 | Unity UI简介–第2部分(7)

本期我们继续为大家进行Unity UI简介&#xff08;第二部分&#xff09;的后续教程 本篇内容 12.在菜单场景中添加音乐 13.开启和关闭音乐 文章末尾可免费获取教程源代码 本篇本篇Unity UI简介&#xff08;第二部分&#xff09;篇幅较长&#xff0c;分为八篇&#xff0c;本…

对称加密算法(三)(DES)

文章目录DES EncryptionDES DecryptionExampleThe Avalanche EffectThe Strength of DESThe Use of 56-Bit KeysThe Nature of the DES AlgorithmReferences在 2001 年引入 AEC&#xff08;Advanced Encryption Standard&#xff09;之前&#xff0c;最为普遍使用的加密机制就是…

Python里面的xlrd模块详解

那我就一下面积个问题对xlrd模块进行学习一下&#xff1a; 1.什么是xlrd模块&#xff1f; 2.为什么使用xlrd模块&#xff1f; 3.怎样使用xlrd模块&#xff1f; 1.什么是xlrd模块&#xff1f; ♦python操作excel主要用到xlrd和xlwt这两个库&#xff0c;即xlrd是读excel&…

SQL 入门篇之什么是别名?

SQL 入门篇之什么是别名&#xff1f; &#x1f4d2;博客主页&#xff1a; ​​开心档博客主页​​ &#x1f389;欢迎关注&#x1f50e;点赞&#x1f44d;收藏⭐留言&#x1f4dd; &#x1f4cc;本文由开心档原创&#xff01; &#x1f4c6;51CTO首发时间&#xff1a;&#x1…

计算机研究生就业方向之考公

我一直跟学生们说你考计算机的研究生之前一定要想好你想干什么&#xff0c;如果你只是转码&#xff0c;那么你不一定要考研&#xff0c;至少以下几个职位研究生是没有啥优势的&#xff1a; 1&#xff0c;软件测试工程师&#xff08;培训一下就行&#xff09; 2&#xff0c;前…

一篇文章带你了解Linux内核进程上下文切换

&#xff11;&#xff0e;进程上下文的概念 进程上下文是进程执行活动全过程的静态描述。我们把已执行过的进程指令和数据在相关寄存器与堆栈中的内容称为进程上文&#xff0c;把正在执行的指令和数据在寄存器与堆栈中的内容称为进程正文&#xff0c;把待执行的指令和数据在寄…

【SpringMVC】HiddenHttpMethodFilter 转换请求方式

由于浏览器只支持发送get和post方式的请求&#xff0c;那么该如何发送put和delete请求呢&#xff1f; SpringMVC 提供了 HiddenHttpMethodFilter 帮助我们将 POST 请求转换为 DELETE 或 PUT 请求 HiddenHttpMethodFilter 处理put和delete请求的条件&#xff1a; 当前请求的请求…

软考《系统集成项目管理工程师》必备100题(1)

新一轮软考备考来啦~为了帮助大家提高备考效率&#xff0c;将2023上半年软考《系统集成项目管理工程师》必备100题&#xff0c;分享给大家&#xff0c;快来跟着一起打卡学习吧&#xff01; 有电子版的&#xff0c;可以打印下来背诵~ 1.项目管理过程组有哪些? 启动过程组:定…

aspose win/linux WORD转PDF(及其解决乱码方式)

aspose win/linux WORD转PDF&#xff08;及其解决乱码方式&#xff09;1.工具类2.控制台3.解决乱码4.JAR包之前自己用的docm4j 本地进行转换是ok 在服务器中就异常了&#xff1b; 后来在网上查询之后 do4j无法支持liunx系统&#xff1b; 1.工具类 package com.aostar.ida.fra…

LabVIEW在面向对象编程中利用硬件抽象层(HAL)设计2

LabVIEW在面向对象编程中利用硬件抽象层(HAL)设计2 这部分是< LabVIEW在面向对象编程中利用硬件抽象层(HAL)设计1>的下半部分。 一体化项目 因此&#xff0c;部署为打包库&#xff0c;实际上有多种方法来开发代码:首先&#xff0c;将查看all-in-one项目方法。父类和子…

python numpy 的输出控制

示例代码&#xff1a; import numpy as np #precision: xnp.array([3.1415926]) print(x) np.set_printoptions(precision4) print(x)#threshold: xnp.arange(0,12,1) print(x) np.set_printoptions(threshold7) print(x)#edgeitems: xnp.arange(0,12,1) print(x) np.set_prin…

【大数据】clickhouse 常用语法规则优化策略详解

一、前言 在之前的文章中&#xff0c;我们了解到clickhouse作为一款列式存储数据库 &#xff0c;查询性能非常高效&#xff0c;一方面与其自身的存储引擎设计有关&#xff0c;另一方面&#xff0c;在执行查询语句时&#xff0c;底层做了大量的语法规则的优化&#xff0c;本文将…

一体化闸门控制机如何使用

一体化闸门控制机是一款集水位采集、流量计算、图片视频采集、远程通讯、远程控制、本地控制于一体的闸门自动化、信息化测控设备&#xff0c;能够在监控中心远程启闭以及闸门手/自动控制;并通过实时图像监控可以直观了解闸门的运行工况以及周边环境。 1、设备介绍 闸门自动化…

Windows11 Docker镜像存储路径更改(非C盘路径)

Windows11 Docker镜像存储路径更改&#xff08;非C盘路径&#xff09; 基于WSL2安装docker后&#xff0c;在使用过程中会发现大量的docker镜像文件&#xff0c;使系统C盘容量激增&#xff0c;对电脑后续使用造成不便&#xff0c;所以需要在安装的时候&#xff0c;手动修改dock…

已开发多款原型,或明年发布新品,三星XR专利布局大揭秘

近期据韩媒Naver新闻爆料&#xff0c;三星电子或将于明年面向开发者推出XR头显&#xff0c;以构建XR生态系统。据悉&#xff0c;三星计划通过打造XR生态系统&#xff0c;来整合元宇宙、软件、内容、元件开发和科研等上下游领域。据称&#xff0c;为了开发XR设备&#xff0c;三星…

数据仓库电商业务简介完整使用 (第二章)

电商业务简介一、电商业务简介1、电商业务流程2、电商常识1&#xff09;SKU和SPU2&#xff09;平台属性和销售属性1&#xff09;平台属性2&#xff09;销售属性二、业务数据介绍1、电商系统表结构1、活动信息表&#xff08;activity_info&#xff09;2、动规则表&#xff08;ac…

【Docker】解决Docker创建Tomcat容器实例后访问Tomcat主页时报HTTP状态404-未找到的错误

专栏精选文章 《Docker是什么&#xff1f;Docker从介绍到Linux安装图文详细教程》《30条Docker常用命令图文举例总结》《Docker如何构建自己的镜像&#xff1f;从镜像构建到推送远程镜像仓库图文教程》《Docker多个容器和宿主机之间如何进行数据同步和数据共享&#xff1f;容器…