(1)
//通过tag来找到需要的东西
- (UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self
例如:
for (int i = 0; i<titleAry.count; i++) {
JECellStyle style = JECellInput;
if(i == titleAry.count -1) style =JECellDisclosureIndicator;
else if(i ==2) style =JECellTheList;
JECell *cell = [[JECellalloc]initWithFrame:ccr(0, i*40,SCREEN_WIDTH - 20, 40) style:style];
cell.tag = i+100;
cell.titleLab.textColor = titleColor;
cell.titleLab.text = titleAry[i];
[self.imageViewaddSubview:cell];
}
此后可以通过tag获取:
JECell *cell = (JECell *)[self.viewviewWithTag:102];
(2)UIImageView默认是不存在用户交互的,也就是说假如在上面加个button,buttonAction会失效,解决办法:调用
setUserInteractionEnabled:方法。
2月
(1)学会使用宏定义,对于那些重复写的代码并且可能要修改的,尽量使用宏定义,比如:说内容的字体,控件之间的间距等等。。。
(2)有的时候我们需要判断某个点是否在某个区域内。。。调用方法: CGRectContainsPoint(<#CGRect rect#>, <#CGPoint point#>);
例如: if (CGRectContainsPoint(btn.frame, point)) {
return yes;
}
7月
通知的注册与销毁
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//** 注册键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//** 将通知监听器销毁
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}