总结iOS 开发中遇到的问题和解决方法
NSString
去掉 NSString
中的空格和换行,stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]
但是这只能去掉头部和尾部的空格和换行符,中间的没法去掉。
如果去掉两端的空格和换行后,需要将中间的去掉,结合下面的方法。
NSArray *components = [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
string = [components componentsJoinedByString:@""];
替换NSString
中指定的字符,
[string stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSNotificationCenter
NSNotificationCenter
使用顺序,addObserver
在先, 而后postNotificationName
;
可能crash 的原因,
- 使用后没有
removeObserver
,在升级xcode 7.3
后遇到过,从而导致crash; -
post
操作的线程和addObserver
的线程不一致而引发的。南峰子博客 Notification与多线程;
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidCompleteNotification object:task userInfo:userInfo];
});
修改UITextField
placeholder 的字体大小和颜色
[textField setValue:placeHolderColor forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:placeHolderFont forKeyPath:@"_placeholderLabel.font"];
网友评论