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();  
            }  
        }];  
    }  

 

转载于:https://www.cnblogs.com/duke-cui/p/4678072.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值