先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
正文
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:[ViewControllernew]];
self.window.rootViewController = nav;
nav.navigationBar.translucent = NO;
[self.windowmakeKeyAndVisible];
return YES;
}
新建一个继承于UIViewController
的视图控制器,命名为NextViewController
,为方便讲解,令ViewController
为A,NextViewController为B。并在两个控制器分别放上一个button和一个label,label作为属性,button增加一个点击事件。
在ViewDidLoad
中加入如下代码:
self.view.backgroundColor = [UIColor blueColor];
UIButton *btnProperty = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnProperty.frame = CGRectMake(100,60, 175, 40);
[btnProperty setTitle:@"属性传值"forState:UIControlStateNormal];
[btnProperty addTarget:self action:@selector(btnProperty)forControlEvents:UIControlEventTouchUpInside];
[btnProperty setBackgroundColor:[UIColorgreenColor]];
[self.view addSubview:btnProperty];
[self.view addSubview:self.lblProperty];
另外给self.lblProperty
做一个懒加载:
- (UILabel *)lblProperty{
if (!_lblProperty) {
_lblProperty = [[UILabel alloc]initWithFrame:CGRectMake(100,20, 175, 30)];
_lblProperty.backgroundColor = [UIColor whiteColor];
}
return _lblProperty;
}
在NextViewController也加入相同代码,只需把界面颜色换一下区分开即可;
二、属性传值
属性传值即给相应的ViewController
定义一个外部可用的属性,在界面跳转时传送相应的值,所有传值都可分为A–>B和B–>A,其中A为源视图,B为目标视图。
2.1 属性传值A–>B
通过属性由A传值到B不难理解,只需要在B界面定义一个属性,在A PUSH到B的时候把需要传送的内容赋值给B对应的属性即可,代码如下:
- 在NextViewController.h 定义一个属性(本文以字符串为例):
@property (nonatomic,strong) NSString *strProperty2;
- 在ViewController中的点击事件做如下操作:
//属性传值
- (void)btnProperty{
NextViewController *nextVC = [[NextViewControlleralloc]init];
nextVC.strProperty2 = @“shq5785”;
[self.navigationController pushViewController:nextVC animated:YES];
}
- 这时B控制器已经拿到了A传来的值,只需要在
viewDidLoad
做个赋值操作即可展现出传过来的字符串了:
//属性传值
self.lblProperty.text =self.strProperty2;
2.2 属性传值B–>A
属性由B到A传值会比A到B稍微复杂一点,不过也是分为三步:
- 给A定义一个外部可用属性:
@property (nonatomic,strong) NSString *strProperty1;
- 在B跳转回A的点击事件中找到A控制器并给其属性赋值,这里拿到A控制器就不能跟A–>B那样直接新建一个控制器了,因为A控制器还存在,只是没有显示出来而已;所以应该通过导航栏控制器中获取当前A控制器:
- (void)btnProperty{
ViewController *VC =self.navigationController.viewControllers[0];
VC.strProperty1 = @“iOS”;
[self.navigationController popViewControllerAnimated:YES];
}
- 这时A中已经拿到了B传过来的值,但是要显示的话应该在
viewWillAppear
中处理:
- (void)viewWillAppear:(BOOL)animated{
// 属性传值
self.lblProperty.text = self.strProperty1;
}
三、代理传值
3.1 代理传值A–>B
3.1 在A控制器的头文件申明协议:
@protocol ViewControllerDelegate
@optional
- (void)delegateSendToNext:(NSString * )strDelegate;
@end
- 在
@interface
中添加遵循协议的代理属性
@property (nonatomic,assign)id delegate;
- 在B的头文件中遵循A的协议;
@interface NextViewController :UIViewController
- 在A跳转到B的点击事件中,让B界面成为A的代理,并调用代理方法;
//代理传值
- (void)btnDelegate{
NextViewController *nextVC = [[NextViewController alloc]init];
self.delegate = nextVC;
[self.delegate delegateSendToNext:@“shq5785”];
[self.navigationController pushViewController:nextVC animated:YES];
}
- 在B控制器实现A协议中的方法完成传值。
//在B控制器实现A控制器中的代理方法
- (void)delegateSendToNext:(NSString * )strDelegate{
self.lblDelegate.text = strDelegate;
}
3.2 代理B–>A
- 在B控制器头文件申明协议;
@protocol NextViewControllerDelegate
@optional
- (void)delegateSend:(NSString *)strDelegate;
@end
- 在B控制器定义遵循协议的属性;
@property (nonatomic,assign) id delegate;
- 在B跳回A的点击事件中调用代理方法;
- (void)btnDelegate{
[self.delegate delegateSend:@“iOS”];
[self.navigationController popViewControllerAnimated:YES];
}
- A遵循B的协议;
@interface ViewController ()
- 在A跳转到B的点击事件中使A成为B的代理者;
//代理传值
- (void)btnDelegate{
NextViewController *nextVC = [[NextViewController alloc]init];
nextVC.delegate = self;
[self.navigationController pushViewController:nextVC animated:YES];
}
- 在A控制器实现B协议中的代理方法;
//代理方法
- (void)delegateSend:(NSString *)strDelegate{
self.lblDelegate.text = strDelegate;
}
四、通知传值
通知传值的核心部分,就是建立好监听者与发送者在时间上的关系,即一定要先有监听者再去发送通知,掌握好了这一点就可以玩转通知传值。
4.1 通知传值A–>B
- B是消息的接收者,要在A发送消息之前先建立好监听者,这时候就需要在B中重写
init
方法来达到这个目的,然后写收到通知后的操作,最后一定要记得移除监听者,否则会造成内存泄漏;
- (instancetype)init{
if (self = [superinit]) {
//创建监听者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValue:) name:@“bobo” object:nil];
}
return self;
}
//通知传值
- (void)changeValue:(NSNotification *)notification{
NSDictionary * dict = notification.userInfo;
self.lblNotification.text = dict[@“key”];
}
//移除监听者
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@“bobo” object:nil];
}
- 接下来就是在A的点击事件中添加发送消息即可。
// 通知传值
- (void)btnNotification{
NextViewController *nextVC = [[NextViewController alloc]init];
NSNotification *notification = [[NSNotification alloc]initWithName:@“bobo” object:nil userInfo:@{@“key”😡“shq5785”}];
// 发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
[self.navigationController pushViewController:nextVC animated:YES];
}
4.2 通知传值B–>A
- 由B到A传值就更简单了,因为时间顺序上一定是先有A后有B,所以只要在A的
viewDidLoad
中建立一个监听者,然后实现监听事件,最后一处监听者就行
//在viewDidLoad中注册监听者
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeValue:) name:@“bobo2” object:nil];
//收到通知后操作
- (void)changeValue:(NSNotification *)notification{
NSDictionary *dict = notification.userInfo;
self.lblNotification.text = dict[@“key”];
}
//移除监听者
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self name:@“bobo2” object:nil];
}
- 在B跳转回A的时候发送通知就行了。
- (void)btnNotification{
NSNotification * notification = [[NSNotification alloc]initWithName:@“bobo2” object:nil userInfo:@{@“key”😡“iOS”}];
//发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
[self.navigationController popViewControllerAnimated:YES];
}
五、单例传值
单例,就是从程序开始到程序结束不管中途怎么去实例化都只有一个实例对象,先创建一个单例(本文已Teacher类作为单例示例):
//Teacher.h
#import <Foundation/Foundation.h>
@interface Teacher :NSObject<NSCopying,NSMutableCopying>
@property (nonatomic,strong) NSString * name;
@property (nonatomic,assign) int age;
- (instancetype)shareInstance;
@end
//Teacher.m
#import “Teacher.h”
更多面试题
**《350页前端校招面试题精编解析大全》**内容大纲主要包括 HTML,CSS,前端基础,前端核心,前端进阶,移动端开发,计算机基础,算法与数据结构,项目,职业发展等等
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
//Teacher.m
#import “Teacher.h”
更多面试题
**《350页前端校招面试题精编解析大全》**内容大纲主要包括 HTML,CSS,前端基础,前端核心,前端进阶,移动端开发,计算机基础,算法与数据结构,项目,职业发展等等
[外链图片转存中…(img-A9BEPyLF-1713676668949)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-8pfZgNzj-1713676668949)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!