原文地址:http://shavekevin.com/2016/04/12/iosdeveloptips/
1.取消cell的分割线
tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
2.UITabelviewCell 的高亮状态的取消
用以下方法:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//设置cell的背景是透明的。
cell.backgroundColor = [UIColor clearColor];
//取消cell的高亮状态
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//使用下面的这个方法会导致cell不能响应点击事件
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
3.设置分割线的左右偏移量
tableview setSeparatorInset:inset
4.推送如何跳转到对应的controller
跳转界面
- (void)push:(NSDictionary *)params
{
// 类名
NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];
const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];
// 从一个字串返回一个类
Class newClass = objc_getClass(className);
if (!newClass)
{
// 创建一个类
Class superClass = [NSObject class];
newClass = objc_allocateClassPair(superClass, className, 0);
// 注册你创建的这个类
objc_registerClassPair(newClass);
}
// 创建对象
id instance = [[newClass alloc] init];
// 对该对象赋值属性
NSDictionary * propertys = params[@"property"];
[propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
// 检测这个对象是否存在该属性
if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) {
// 利用kvc赋值
[instance setValue:obj forKey:key];
}
}];
// 获取导航控制器
UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex];
// 跳转到对应的控制器
[pushClassStance pushViewController:instance animated:YES];
}
检测对象是否存在该属性
- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName
{
unsigned int outCount, i;
// 获取对象里的属性列表
objc_property_t * properties = class_copyPropertyList([instance
class], &outCount);
for (i = 0; i < outCount; i++) {
objc_property_t property =properties[i];
// 属性名转成字符串
NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
// 判断该属性是否存在
if ([propertyName isEqualToString:verifyPropertyName]) {
free(properties);
return YES;
}
}
free(properties);
return NO;
}
来源于简书: iOS 万能跳转界面方法 runtime实用篇一
7.3D效果 还不错哦
https://github.com/nicklockwood/iCarousel
8.xcode7引入xmpp提示module libxmlsimu not found怎么解决?
解决方案如下图:
9.data进行MD5 加密
10.UIVisualEffectView 背景是虚化的(类似我们iphone查看通知时的虚化背景)
https://github.com/nicklockwood/FXBlurView
11.NSDate 的坑
Also when using a date format string using the correct format is important.
@"YYYY" is week-based calendar year.
@"yyyy" is ordinary calendar year.
可以看下面这篇博客:NSDateFormatter 'YYYY' 和 'yyyy' 的区别
12.swift 实时滤镜
http://blog.youkuaiyun.com/zhangao0086/article/details/39433519
13.动态加载视频
http://www.jianshu.com/p/3dcebf0493d1
14.swift 闭包
http://www.henishuo.com/closures-of-swift/
15.理解contentsScale
http://joeshang.github.io/2015/01/10/understand-contentsscale/#disqus_thread
16.图文混排
https://github.com/12207480/TYAttributedLabel
19.textField 文字上下居中
textField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
//.全部删除按钮
textField.clearButtonMode =UITextFieldViewModeWhileEditing;
[textFieldsetAutocapitalizationType:UITextAutocapitalizationTypeNone];
26.下面的view或self.view如果小于上面的,上面的view超过下面的部分将无法与用户交互。
27.自定义cell时,最好在cell.contentView上加控件
29.正则
(?<=src\s*\=\s*\")[\d\D]+?(?=\")
取出html 中的src 图片
32.dealloc的super dealloc必须放在最后面
33.所有不带星号的和id类型的都只能assign
39.程序崩溃处理方法
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
}
调用下面的方法,如数组越界,调用不存在的方法等会打出详细的信息。
void UncaughtExceptionHandler(NSException*exception) {
NSArray *arr = [exception callStackSymbols];
NSString *reason = [exception reason];
NSString *name = [exception name];
NSLog(@"\nname: %@\reason: %@\nuserInfo: %@\ncallStackSymbols:%@\ncallStackReturnAddresses: %@",name,reason,[exceptionuserInfo],arr,[exceptioncallStackReturnAddresses]);
}
开启僵尸模式 Object-C的Enable Zombie Objects勾选,Memory 中的MallocStack勾选,Exceptions里的Log Exceptions勾选
40.NSLog 怎么打印出变量类型的?
NSStringFromSelector(SEL aSelector);
NSSelectorFromString(NSString *aSelectorName);
NSStringFromClass(Class aClass);
NSClassFromString(NSString *aClassName);
NSStringFromProtocol(Protocol *proto)
NSProtocolFromString(NSString *namestr)
NSStringFromCGPoint(CGPoint point);
NSStringFromCGVector(CGVector vector);
NSStringFromCGSize(CGSize size);
NSStringFromCGRect(CGRect rect);
NSStringFromCGAffineTransform(CGAffineTransform transform);
NSStringFromUIEdgeInsets(UIEdgeInsets insets);
NSStringFromUIOffset(UIOffset offset);
CGPointFromString(NSString *string);
CGVectorFromString(NSString *string);
CGSizeFromString(NSString *string);
CGRectFromString(NSString *string);
CGAffineTransformFromString(NSString *string);
UIEdgeInsetsFromString(NSString *string);
UIOffsetFromString(NSString *string);