博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Day4
阅读量:4599 次
发布时间:2019-06-09

本文共 2829 字,大约阅读时间需要 9 分钟。

1 Strong and Weak

#import "Person.h"@implementation Person- (void)dealloc{    NSLog(@"person destroy");}@end

强指针:strong系统一般不会自动释放

弱指针:weak 系统会立即释放对象

////  ViewController.m//  BasicKnowledge////  Created by xin on 15-3-16.//  Copyright (c) 2015年 Jackey. All rights reserved.//#import "ViewController.h"#import "Person.h"@interface ViewController ()@property (nonatomic,strong) Person *person;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.            //strong pointer    //won't release the memory    //默认的是强指针    //不执行销毁语句    self.person = [[Person alloc]init];        //这里是强指针,但是这是个局部对象,在viewdidload执行完后会执行销毁语句    Person *person1 = [[Person alloc]init];        //立即释放    __weak Person *person2 = [[Person alloc]init];    //strong weak 的区别:    //strong为持有者,weak为观望者,就像strong是一条狗链子    NSLog(@"-----");}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end
////  ViewController.m//  BasicKnowledge////  Created by xin on 15-3-16.//  Copyright (c) 2015年 Jackey. All rights reserved.//#import "ViewController.h"#import "Person.h"@interface ViewController ()@property (nonatomic,strong) Person *person;@property (nonatomic,weak) Person *weakPerson;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.            //strong pointer    //won't release the memory    //默认的是强指针    //不执行销毁语句    //体现strong和weak的区别    //strong 为持有者,牵着person对象,weakperson为虚指向person对象    //下面的情况,weakperson不会被自动销毁    self.person = [[Person alloc]init];    self.weakPerson = self.person;        NSLog(@"-----");}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

weak指针一般指向strong pointer的对象

//拖拉的控件用weak    //属性对象用strong    //整数非对象类型用assign   //NSString 用copy

2 block的使用

-(void)downloadClick:(UIButton *)button{    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(80, 400, 160, 40)];    lable.textAlignment = NSTextAlignmentCenter;    lable.backgroundColor = [UIColor lightGrayColor];    NSDictionary *dict = self.appList[button.tag];    lable.text = [NSString stringWithFormat:@"下载%@完成",dict[@"name"]];        lable.font = [UIFont systemFontOfSize:13.0];    lable.alpha = 0.0;    [self.view addSubview:lable];        //动画效果    //[UIView beginAnimations:nil context:nil];    //[UIView setAnimationDuration:1.0];    //lable.alpha = 1.0;    //[UIView commitAnimations];        [UIView animateWithDuration:1.0 animations:^{        lable.alpha=1.0;    } completion:^(BOOL finished) {        [lable removeFromSuperview];    }];        }

  

 

转载于:https://www.cnblogs.com/lihaozhou/p/4342573.html

你可能感兴趣的文章
bellman ford优先队列优化简介模板
查看>>
TCP三次握手
查看>>
ASP.NET AJAX调用 WebService
查看>>
大学三年的反思
查看>>
Get和Post的区别(转)
查看>>
数据库sql中distinct用法注意事项
查看>>
linux系统下单节点hadoop2的配置
查看>>
PAT (Basic Level) Practise 1006. 换个格式输出整数
查看>>
Ubuntu Eclipse 提示颜色
查看>>
温习 数据结构之HuffmanTree
查看>>
dva reduxRouter 跳转路由的参数
查看>>
Code Pages
查看>>
How do I force my .NET application to run as administrator?
查看>>
应该知道的30个jQuery代码开发技巧
查看>>
PHP与ASP.NET的优劣比较
查看>>
Dapper使用动态参数
查看>>
Vue的安装及使用快速入门
查看>>
Java_包装类
查看>>
ubuntu14.04安装与配置nginx服务器
查看>>
利用/dev/urandom文件创建随机数
查看>>