tableview cell点击高亮松开高亮小时
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
view添加边框(添加layer属性值)
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
CALayer *bottomBorder = [CALayer layer];
float height1=view.frame.size.height-0.5f;
float width1=view.frame.size.width;
bottomBorder.frame = CGRectMake(0.0f, height1, width1, 0.5f);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
[view.layer addSublayer:bottomBorder];
log 宏
#define DDLog(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
例子
DDLog(@"%@",@"我是log");
给对象事件添加多个参数(不仅限于按钮)
** 利用ObjC关联
NSDictionary *param = @{@"name":@"小明",@"age":@"25",@"favorite":@"eat"};//想要传的参数
UIButton *clickButton = /*...*/ create button
[clickButton addTarget:self action:@selector(testClick:) forControlEvents:UIControlEventTouchUpInside];
objc_setAssociatedObject(clickButton, "param", param, OBJC_ASSOCIATION_RETAIN_NONATOMIC); //参数(按钮,参数key,参数对象,关联策略)
//测试方法
- (void)testClick:(UIButton *)sender{
NSDictionary *param = objc_getAssociatedObject(sender, "param"); //取参
NSLog(@"first: %@",param);
}
/*
打印结果:
2016-06-22 10:34:45.879081+0800 TestProject[3097:222603] param: {
age = 25;
favorite = eat;
name = "小明";
}
*/
tip:别忘记导入runtime
#import <objc/runtime.h>
extern 修饰符
*用来获取在其他类中定义的全局变量(包括全局静态变量)的值,不能用于定义变量(常用于某个变量整个项目查看及修改的变量)
例子:
aController.m
NSString *externString = @"234";//全局变量定义
@interface aController ()
@end
@implementation aController
bController.m
extern NSString *externString;//全局变量定义
@interface bController ()
@end
@implementation bController
- (void)viewDidLoad {
NSLog(@"externString: %@",externString);//externString:234
externString = @"10086";
NSLog(@"externString: %@",externString);//externString:10086
}
tips:可将定义写在Appdelegate中,然后将extern写在pch文件中,以达到整个项目所有文件无需再次extern即可直接 使用externString变量的目的。