zoukankan      html  css  js  c++  java
  • 去除警告,打电话,发信息,应用程序之间跳转,打印沙盒路径,字符串名字转换方法,包装导航控制器等的代码

    从偏好设置中读取值:

    打电话代码:

    发信息代码:

    打印沙盒路径代码:

    应用程序之间跳转代码:

    跳转到苹果商店代码:

    去除警告代码:

    根据字符串名称转换成相对应方法的代码:

    #import "SZMSettingsCell.h"
    
    @implementation SZMSettingsCell
    
    //选择不同的cell类型
    + (UITableViewCellStyle)cellStyleWithDict:(NSDictionary *)dict{
        
        UITableViewCellStyle cellStyle = UITableViewCellStyleDefault;
        
        if ([dict[@"cellStyle"]isEqualToString:@"UITableViewCellStyleSubtitle"]) {
            cellStyle = UITableViewCellStyleSubtitle;
        }else if ([dict[@"cellStyle"]isEqualToString:@"UITableViewCellStyleValue1"]){
            cellStyle = UITableViewCellStyleValue1;
        }else if ([dict[@"cellStyle"]isEqualToString:@"UITableViewCellStyleValue2"]){
            cellStyle = UITableViewCellStyleValue2;
        }
        return cellStyle;
        
    }
    
    
    + (instancetype)settingsCellWithTableView:(UITableView *)TableView withDict: (NSDictionary *)dict{
        
        static NSString *ID = @"id";
        SZMSettingsCell *cell = [TableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [[SZMSettingsCell alloc]initWithStyle:[self cellStyleWithDict:dict] reuseIdentifier:ID];
        }
        return cell;
    }
    
    - (void)setItem:(NSDictionary *)item{
        _item = item;
        
        //给cell设置文字
        self.textLabel.text = item[@"title"];
        //给cell设置图片
        if (item[@"icon"]) {
            self.imageView.image = [UIImage imageNamed:item[@"icon"]];
        }
        //给cell详细信息
        if (item[@"details"] && [item[@"details"] length] > 0) {
            self.detailTextLabel.text = item[@"details"];
            //判断cell的详细信息文字是否需要变为红色
            if (item[@"isHighlighted"]) {
                self.detailTextLabel.textColor = [UIColor redColor];
            }
        }
        
        //判断当前cell中的details信息,是否在偏好设置中已经设置好了
        if (item[@"detailsKeyName"]) {
            //从偏好设置中读取存储的内容
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            
            NSString *text = [defaults objectForKey:item[@"detailsKeyName"]];
            
            //如果存储的内容不为空
            if (text) {
                self.detailTextLabel.text = text;
            }
        }
        
        //设置右侧的accessoryview
        if (item[@"accessory"]) {
            //根据配置文件中的字符串(item[@"accessory"]在plist文件中对应的字符串)来创建对应的类
            Class accessoryCalss = NSClassFromString(item[@"accessory"]);
            
            //创建这个类型的对象
            id obj = [[accessoryCalss alloc]init];
            
            if ([obj isKindOfClass:[UIImageView class]]) {
                //表示是图片框
                UIImageView *imgView = (UIImageView *)obj;
                imgView.image = [UIImage imageNamed:item[@"accessoryImage"]];
                //调整图片框与图片大小相同
                [imgView sizeToFit];
            }
            
            //设置cell的accessoryView为动态的创建的这个类型
            self.accessoryView = obj;
            
            //判断如果是开关,注册一个valueChange事件
            if ([obj isKindOfClass:[UISwitch class]]) {
                UISwitch *switcher = (UISwitch *)obj;
                [switcher addTarget:self action:@selector(swithcValueChanged:) forControlEvents:UIControlEventValueChanged];
                
                //从偏好设置中读取开关的值,并设置
                NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                //读取
                switcher.on = [userDefault boolForKey:self.item[@"keyName"]];
            }
            
        }
    }
    
    - (void)swithcValueChanged:(UISwitch *)sender{
        //获取开关的状态
        //把开关状态保存到偏好设置中
        NSUserDefaults *userDefu = [NSUserDefaults standardUserDefaults];
        [userDefu setBool:sender.isOn forKey:self.item[@"keyName"]];
        [userDefu synchronize];
        
    }
    - (void)setTime:(NSString *)str{
        self.detailTextLabel.text = str;
        //把时间交给偏好设置进行记录
        NSUserDefaults *userDefu = [NSUserDefaults standardUserDefaults];
        [userDefu setObject:str forKey:self.item[@"detailsKeyName"]];
        [userDefu synchronize];
    }

    把一个控制器包装成导航控制器的代码:

  • 相关阅读:
    asp.net保存远程图片
    JS中的转义字符
    SQL_统计某列的和
    SQL Server 出错自动回滚
    SQL中的循环语句_类似FOR循环
    转 C# 控制IE
    抓取html 写正则
    正则截取内容
    用于测试的字符串
    C#关闭IE相应的窗口 .
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5041751.html
Copyright © 2011-2022 走看看