zoukankan      html  css  js  c++  java
  • IOS 随记

    1、自定义构造方法

    - (id) initWithAge:(int)age andNo:(int)no {

        // 首先要调用super的构造方法

        // self = [super init];

        if (self = [super init]) {

             _age = age;

             _no = no;

        }

        return self;

    }

    2、重写父类的description方法

    在entity中重写父类description 方法,在NSLog(@"%@",entity)打印entity时不再显示内存地址,而是显示description 返回的字符串。

    - (NSString *)description {

        NSString *str = [NSString stringWithFormat:@"age is %i and no is %i", self.age, self.no];

        return str;

    }

    定义数组

    NSArray *allNames = @[@"西门庆", @"东门庆", @"北门庆", @"南门庆", @"中门庆"];

    //  取出最后一个子控件
    UIView *last = [self.view.subviews lastObject];

    // 通过Tag获取控件

    [btn.superview viewWithTag:10];

    // 剩下的子控件个数 > 1就能够点击“删除”
    _removeItem.enabled = self.view.subviews.count > 1;

    // 创建一个随机数

        int ramdomIndex = arc4random() % 9;
        int randomIndex = arc4random_uniform(9);

    // 设置文字居中
    name.textAlignment = NSTextAlignmentCenter;

    // 1.加载RowView.xib文件,创建Objects下面的所有控件,并且按顺序装到数组中返回
    NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"RowView" owner:nil options:nil];

    // 2.取出一行的红色view
    UIView *rowView = views[0];

    // 1.获得即将删除的这行在数组中的位置
    int startIndex = [self.view.subviews indexOfObject:btn.superview];

    XIB 的重用:

    1、调用方法

    RowView *row = [RowView rowViewWithIcon:@"017.png" name:@"哈哈哈"];
        
    [self.view addSubview:row];
    //
    //  RowView.h
    //  01-联系人管理
    //
    //  Created by apple on 13-11-25.
    //  Copyright (c) 2013年 itcast. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface RowView : UIView
    + (id)rowViewWithIcon:(NSString *)icon name:(NSString *)name;
    
    
    @property (nonatomic, weak) IBOutlet UIButton *iconBtn;
    
    @property (nonatomic, weak) IBOutlet UILabel *nameLabel;
    
    @end
    //
    //  RowView.m
    //  01-联系人管理
    //
    //  Created by apple on 13-11-25.
    //  Copyright (c) 2013年 itcast. All rights reserved.
    //
    
    #import "RowView.h"
    
    @implementation RowView
    
    + (id)rowViewWithIcon:(NSString *)icon name:(NSString *)name
    {
        RowView *view = [[NSBundle mainBundle] loadNibNamed:@"RowView" owner:nil options:nil][0];
        
        // 1.设置图标
    //    UIButton *iconBtn = (UIButton *)[view viewWithTag:1];
        [view.iconBtn setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
        
        // 2.设置姓名
    //    UILabel *nameLabel = (UILabel *)[view viewWithTag:2];
        view.nameLabel.text = name;
        
        return view;
    }
    
    
    
    @end

    禁止UIwebview 回弹

    [(UIScrollView *)[[webview subviews] objectAtIndex:0] setBounces:NO];

    终端将.p12 证书转为.pem

    需要通过终端命令将这些文件转换为PEM格式:openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12

        + (void)postUploadWithUrl:(NSString *)urlStr fileUrl:(NSURL *)fileURL fileName:(NSString *)fileName fileType:(NSString *)fileTye success:(void (^)(id responseObject))success fail:(void (^)())fail  
        {  
            // 本地上传给服务器时,没有确定的URL,不好用MD5的方式处理  
            AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];  
            manager.responseSerializer = [AFHTTPResponseSerializer serializer];  
            //@"http://localhost/demo/upload.php"  
            [manager POST:urlStr parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {  
                  
        //        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"头像1.png" withExtension:nil];  
                  
                // 要上传保存在服务器中的名称  
                // 使用时间来作为文件名 2014-04-30 14:20:57.png  
                // 让不同的用户信息,保存在不同目录中  
        //        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];  
        //        // 设置日期格式  
        //        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";  
        //        NSString *fileName = [formatter stringFromDate:[NSDate date]];  
                  
                //@"image/png"  
                [formData appendPartWithFileURL:fileURL name:@"uploadFile" fileName:fileName mimeType:fileTye error:NULL];  
                  
            } success:^(AFHTTPRequestOperation *operation, id responseObject) {  
                if (success) {  
                    success(responseObject);  
                }  
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {  
                if (fail) {  
                    fail();  
                }  
            }];  
        }  

  • 相关阅读:
    NFS原理
    linux NFS配置案例
    centos swap分区
    git常用命令
    MHA介绍和基础、原理、架构、工具介绍
    mysql5.7.26部署MHA
    mysql5.7.26 基于GTID的主从复制环境搭建
    MHA监控进程异常退出(MHA版本:0.56)
    mysql 主从 Last_IO_Errno错误代码说明
    mysql 在gtid环境下缺少一部分binlog部署从库
  • 原文地址:https://www.cnblogs.com/duke-cui/p/4678072.html
Copyright © 2011-2022 走看看