传值 UI考试知识点

传值:

1. 属性传值:从前往后

2. 代理传值:从后往前

3. block:

4. 单例:普通写法和GCD写法

5 . 通知 NSNotification

GCD 单例:

static PlayMusicHelp *share = nil;

+ (PlayMusicHelp *)shareData {
    if (share == nil) {
        static dispatch_once_t haha;
        dispatch_once(&haha, ^{
            share = [[PlayMusicHelp alloc] init];
        });
    }
    return share;
}

知识点:

1.

UIView 继承于UIResponder,

UIResponder继承于NSObject ,

UIView可以响应用户事件,

CALayer用来绘制内容

2. storyboard:设置cell的自适应高度:

self.tableView.estimatedRowHeight = 44.0f;
self.tableView.rowHeight = UITableViewAutomaticDimension;

3. 本地已存在数据库文件  如何获取:

// 获取指定路径的数据库文件:
    NSString *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [document stringByAppendingPathComponent:@"团购数据"];
    NSString *savePath = [filePath stringByAppendingPathComponent:@"Display.sqlite"];
    if ([[NSFileManager defaultManager]fileExistsAtPath:savePath]) {
        self.db = [FMDatabase databaseWithPath:savePath];
    }

获取完之后,赋给self.db 然后就可以读取数据库里的数据了(通过self.db) 断网的情况下  也可以读取。

4. 将中文进行转码:

NSString *encodedValue2 = [str2 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

5. 计算label高度:

// 计算文字高度 类方法
+(CGFloat)cellHeight:(NSString *)string {
    CGSize size = CGSizeMake(220, 1000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];
    
    CGRect rect = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

6. 指定路径下创建文件夹:

// 1. 创建存储数据的文件夹 :团购数据
    NSString *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSLog(@"文件储存路径:%@", document);
    NSFileManager *manager = [NSFileManager defaultManager];
    NSString *filePath = [document stringByAppendingPathComponent:@"团购数据"];
    [manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
原文地址:https://www.cnblogs.com/Evelyn-zn/p/4962707.html