1:打开Xcode,然后闪退,报加载某库出现异常

如/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
这个是Xcode的bug,我的情况是打开某个项目会出现这个问题
解决办法:这还是缓存问题,详见第五点(、XCode5由于缓存问题引起了很多奇怪的问题,所以清除缓存有时会起到大作用:),清除缓存再运行,一切正常。
进入步骤,按option键进入资源库,Developer—xcode—DerivedData把里面的文件清除就可以

2:加快CocoaPod安装插件的速度

(这样也解决一些插件下载时失败的问题,因为一些源代码的内容是不必要,而提供的地址却连接不到,导致报错,而无法更新)
$ pod install --no-repo-update 

3:userInteractionEnabled属性

当视图对象的userInteractionEnabled设置为NO的时候,用户触发的事件,如触摸,键盘等,将会被该视图忽略(其他视图照常响应),并且该视图对象也会从事件响应队列中被移除。 当userInteractionEnabled设为YES时,则事件可以正常的传递给该视图对象。 userInteractionEnabled的属性默认值就是YES。
EaseUserHeaderView *headerView = [[EaseUserHeaderView alloc] init];
headerView.userInteractionEnabled = YES;

4:字符串显示问题,同一行不同的效果

调用:
[_fansCountBtn setAttributedTitle:[self getStringWithTitle:@"粉丝" andValue:_curUser.fans_count.stringValue] forState:UIControlStateNormal]; 方法:
- (NSMutableAttributedString*)getStringWithTitle:(NSString *)title andValue:(NSString *)value{
NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", value, title]];
[attriString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName : [UIColor whiteColor]}
range:NSMakeRange(, value.length)]; [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:],
NSForegroundColorAttributeName : [UIColor whiteColor]}
range:NSMakeRange(value.length+, title.length)];
return attriString;
} 另:label可以调用sizeToFit来调整内容适应 _userLabel.text = _curUser.name;
[_userLabel sizeToFit];

5:NSArray中使用firstObject和lastObject

NSArray有lastObject方法用来获取数组最后一个对象,firstObject来获取数组第一个对象,NSArray中使用firstObject和lastObject的好处在于,当数组为空时,返回nil,而不会报错。当数组为空,使用myArray[]时,会报错。

NSNumber *firstLevel = nil, *secondLevel = nil;
NSArray *locationArray = [_curUser.location componentsSeparatedByString:@" "];
if (locationArray.count == ) {
firstLevel = [AddressManager indexOfFirst:[locationArray firstObject]];
secondLevel = [AddressManager indexOfSecond:[locationArray lastObject] inFirst:[locationArray firstObject]];
}

6:日期控件ActionSheetDatePicker  多级控件ActionSheetStringPicker

小实例:
NSDate *curDate = [NSDate dateFromString:_curUser.birthday withFormat:@"yyyy-MM-dd"];
if (!curDate) {
curDate = [NSDate dateFromString:@"1990-01-01" withFormat:@"yyyy-MM-dd"];
}
ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:nil datePickerMode:UIDatePickerModeDate selectedDate:curDate doneBlock:^(ActionSheetDatePicker *picker, NSDate *selectedDate, id origin) {
NSString *preValue = weakSelf.curUser.birthday;
weakSelf.curUser.birthday = [selectedDate string_yyyy_MM_dd];
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.birthday = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:^(ActionSheetDatePicker *picker) {
NSLog(@"%@", picker.description);
} origin:self.view];
picker.minimumDate = [[NSDate date] offsetYear:-];
picker.maximumDate = [NSDate date];
[picker showActionSheetPicker]; 小实例: [ActionSheetStringPicker showPickerWithTitle:nil rows:@[[AddressManager firstLevelArray], [AddressManager secondLevelMap]] initialSelection:@[firstLevel, secondLevel] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {
NSString *preValue = weakSelf.curUser.location;
NSString *location = [selectedValue componentsJoinedByString:@" "];
weakSelf.curUser.location = location;
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.location = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:nil origin:self.view]; 小实例: [ActionSheetStringPicker showPickerWithTitle:nil rows:@[@[@"男", @"女", @"未知"]] initialSelection:@[_curUser.sex] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {
NSNumber *preValue = weakSelf.curUser.sex;
weakSelf.curUser.sex = [selectedIndex firstObject];
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.sex = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:nil origin:self.view];

7:代码自动布局Masonry插件

Masonry支持哪一些属性@property (nonatomic, strong, readonly) MASConstraint *left;
@property (nonatomic, strong, readonly) MASConstraint *top;
@property (nonatomic, strong, readonly) MASConstraint *right;
@property (nonatomic, strong, readonly) MASConstraint *bottom;
@property (nonatomic, strong, readonly) MASConstraint *leading;
@property (nonatomic, strong, readonly) MASConstraint *trailing;
@property (nonatomic, strong, readonly) MASConstraint *width;
@property (nonatomic, strong, readonly) MASConstraint *height;
@property (nonatomic, strong, readonly) MASConstraint *centerX;
@property (nonatomic, strong, readonly) MASConstraint *centerY;
@property (nonatomic, strong, readonly) MASConstraint *baseline; 小实例: if (!_titleL) {
_titleL = [[UILabel alloc] init];
[self.contentView addSubview:_titleL];
_titleL.font = [UIFont systemFontOfSize:];
_titleL.textColor = [UIColor blackColor];
}
if (!_valueL) {
_valueL = [[UILabel alloc] init];
_valueL.numberOfLines = ;
[self.contentView addSubview:_valueL];
_valueL.font = [UIFont systemFontOfSize:];
_valueL.textColor = [UIColor colorWithHexString:@"0x999999"];
} [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.height.mas_equalTo();
make.top.equalTo(self.contentView).offset();
make.width.mas_equalTo(kScreen_Width - *kPaddingLeftWidth);
}];
[_valueL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_titleL.mas_bottom).offset();
make.left.right.equalTo(_titleL);
}];
实例(注意右边跟下边要用负数):

UIView *sv=[UIView new];

sv.backgroundColor=[UIColor redColor];

[self.view addSubview:sv];


//定义一个剧中大小


[sv mas_makeConstraints:^(MASConstraintMaker *make) {

        make.center.equalTo(self.view);

make.size.mas_equalTo(CGSizeMake(300, 300));

}];


    UIView *childView=[UIView new];
    childView.backgroundColor=[UIColor greenColor];

[sv addSubview:childView];


//相对父视图

    [childView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.equalTo(sv.mas_left).with.offset(20);

        make.top.equalTo(sv.mas_top).with.offset(10);

make.right.equalTo(sv.mas_right).with.offset(-20);

    

make.height.equalTo(@200);


}];


UIView *otherChildView=[UIView new];

otherChildView.backgroundColor=[UIColor yellowColor];

[sv addSubview:otherChildView];



//相对父视图跟兄弟视图


[otherChildView mas_makeConstraints:^(MASConstraintMaker *make) {


make.top.equalTo(childView.mas_bottom).with.offset(10);


make.bottom.equalTo(sv.mas_bottom).with.offset(-10);


make.left.equalTo(sv.mas_left).with.offset(10);


make.width.mas_equalTo(@240);


}];

另一实例:

// 先给redBtn添加约束


[redBtn mas_makeConstraints:^(MASConstraintMaker *make) {

// 添加左、上边距约束

// 添加上边距约束

        make.top.mas_equalTo(100);
        // 添加左边距约束

make.left.mas_equalTo(20);


// 添加右边距约束

make.right.mas_equalTo(-20);

}];


// 还是老规矩 先初始化一个btn


UIButton * blueBtn = [UIButton new];


blueBtn.backgroundColor = [UIColor blueColor];


[self.view addSubview:blueBtn];


// 给蓝色btn添加约束


[blueBtn mas_makeConstraints:^(MASConstraintMaker *make) {

             // 添加右、下边距约束
        // make.bottom.and.right.mas_equalTo(-20);

// 添加下边距约束

        make.bottom.mas_equalTo(-20);
        // 添加右边距约束
        make.right.mas_equalTo(-20);
        // 添加高度约束,让高度等于红色Btn
        make.height.equalTo(redBtn);
       // 添加上边距约束(上边距 = 红色btn的下边框 + 偏移量20)
        make.top.equalTo(redBtn.mas_bottom).offset(20);

// 添加左边距(左边距 = 父容器纵轴中心 + 偏移量0)

        make.left.equalTo(weakSelf.view.mas_centerX).offset(0);

}];


好文章:http://www.cocoachina.com/ios/20141219/10702.html
关于更新布局mas_updateConstraints的运用

实例一:

#import "Masonry.h"

@interface ViewController5()

@property(strong,nonatomic)UILabel *myLabel;

@end

@implementation ViewController5

-(void)viewDidLoad
{
[super viewDidLoad];
self.myLabel=[UILabel new];
self.myLabel.text=@"GOOD";
self.myLabel.backgroundColor=[UIColor blueColor];
[self.view addSubview:self.myLabel]; [self.myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view.mas_left).with.offset();
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(-);
make.size.mas_equalTo(CGSizeMake(, ));
}];
}
- (IBAction)actionBtn:(id)sender {
CGFloat newBottom=-;
//修改布局
[_myLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(newBottom);
}]; //要进行layoutIfNeeded 才有效果
[self.myLabel layoutIfNeeded];
}
@end 实例二:
(修改键盘跟输入框的隐藏问题)
#import "Masonry.h" @interface ViewController4 () @property (strong, nonatomic) UITextField *textField; @end @implementation ViewController4 - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self];
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. __weak typeof(self) weakSelf = self; _textField = [UITextField new];
_textField.backgroundColor = [UIColor redColor];
[self.view addSubview:_textField]; [_textField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo();
make.centerX.equalTo(weakSelf.view);
make.bottom.mas_equalTo();
make.height.mas_equalTo();
}]; // 注册键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
} - (void)keyboardWillChangeFrameNotification:(NSNotification *)notification { // 获取键盘基本信息(动画时长与键盘高度)
NSDictionary *userInfo = [notification userInfo];
CGRect rect = [userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGFloat keyboardHeight = CGRectGetHeight(rect);
CGFloat keyboardDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改下边距约束
[_textField mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-keyboardHeight);
}]; // 更新约束
[UIView animateWithDuration:keyboardDuration animations:^{ [self.view layoutIfNeeded];
}];
} - (void)keyboardWillHideNotification:(NSNotification *)notification { // 获得键盘动画时长
NSDictionary *userInfo = [notification userInfo];
CGFloat keyboardDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改为以前的约束(距下边距0)
[_textField mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo();
}]; // 更新约束
[UIView animateWithDuration:keyboardDuration animations:^{ [self.view layoutIfNeeded];
}];
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event];
[self.view endEditing:YES];
} @end

IOS客户端Coding项目记录(四)的更多相关文章

  1. IOS客户端Coding项目记录导航

    IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线  表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...

  2. IOS客户端Coding项目记录(五)

    1:统一修改导航栏的样式,在 AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWit ...

  3. IOS客户端Coding项目记录(三)

    18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger ...

  4. IOS客户端Coding项目记录(一)

    1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextFi ...

  5. IOS客户端Coding项目记录(六)

    1:获取某一行的坐标 UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow: ...

  6. IOS客户端Coding项目记录(二)

    9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/m ...

  7. 开源项目在真机调试(Coding iOS 客户端为例)

    一.前言 iOS 13学习系列:如何在github下载开源项目到本地(Coding iOS 客户端为例)已经把 Coding iOS 客户端源码下载到本地. 但项目进行真机调试遇到很多问题. 二.问题 ...

  8. 如何在github下载开源项目到本地(Coding iOS 客户端为例)

    一.前言 以 Coding iOS 客户端 为例讲解如何在github下载开源项目到本地 github地址:https://github.com/Coding/Coding-iOS 二.分析 根据项目 ...

  9. “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX

    "快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...

随机推荐

  1. ListView具有多种item布局——实现微信对话列

    这篇文章的效果也是大家常见的,各种通讯应用的对话列表都是这种方式,像微信.whatsapp.易信.米聊等.我们这篇文章也权当为回忆,形成简单的笔记.这篇文章参考了2009年Google IO中的< ...

  2. 谈mvc开发中gzip压缩的应用

    压缩view的内容,可加过滤器 public class GzipFilter : ActionFilterAttribute     {         public override void O ...

  3. 经典信息图表:2013 扁平设计 VS 拟物设计

    inTacto 是一家互动数字公司,由 Alejandro Lazos 和 Sebastian Caramés 成立于2001年.他们刚刚发布一个信息图表:<平面设计 VS 现实主义>.这 ...

  4. 十分钟搞懂什么是CGI

    原文:CGI Made Really Easy,在翻译的过程中,我增加了一些我在学习过程中找到的更合适的资料,和自己的一些理解.不能算是严格的翻译文章,应该算是我的看这篇文章的过程的随笔吧. CGI真 ...

  5. python常用数据类型内置方法介绍

    熟练掌握python常用数据类型内置方法是每个初学者必须具备的内功. 下面介绍了python常用的集中数据类型及其方法,点开源代码,其中对主要方法都进行了中文注释. 一.整型 a = 100 a.xx ...

  6. redis主从遇到的两个坑

    最近在使用redis主从的时候做了下面两件事情: 1 希望redis主从从操作上分析,所有写操作都在master上写,所有读操作都在从上读. 2 由于redis的从是放在本地的,所以有的key的读写操 ...

  7. 数论 - n元线性同余方程的解法

    note:n元线性同余方程因其编程的特殊性,一般在acm中用的很少,这里只是出于兴趣学了一下 n元线性同余方程的概念: 形如:(a1*x1+a2*x2+....+an*xn)%m=b%m       ...

  8. Oracle Fusion Applications (11.1.8) Media Pack and Oracle Application Development Framework 11g (11.1.1.7.2) for Microsoft Windows x64 (64-bit)

    Oracle Fusion Applications (11.1.8) Media Pack for Microsoft Windows x64 (64-bit) 重新搜索   常见问题    提示  ...

  9. 【iOS】FMDB封装,查询自动mapping

    sqlite几乎所有的App都会用到,但是系统自带的sqlite API是用C语言写的,非常不友好,用起来非常不便,通常我们使用第三方封装好的工具,例如:FMDB(https://github.com ...

  10. win 10 远程连接出现 "由于安全设置错误, 客户端无法连接到远程计算机. 确定你已登录到网络后.” 错误

    win 10 远程连接出现 "由于安全设置错误, 客户端无法连接到远程计算机. 确定你已登录到网络后.” 错误 解决方法如下: Step 1:打开"本地安全策略"- Wi ...