2017.09.27
- 设置button中图片的位置用 _leftbtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0); 这是设置了title相对于左边平移了20 2017.9.29
- 有时候需要获取cell的button的点击事件 然后调到另一个页面
方案一: 写block函数 然后再在父viewcontroller里调用block 如果cell多的话 代码就会很多 pass掉 方案二:在cell中获取父视图的viewcontroller 然后获取navigationcontroller 进行跳转 这样cell复用 中写跳转 省下很多代码 我们创建一个 category 扩展里写自己然后直接调用方法 话不多少 上码 在category 的.h里 //获取当前view的controller -(UIViewController *)getcurrentviewController;
在category 的.m里
-(UIViewController*)getcurrentviewController{
UIResponder *responder = self;
while ((responder = [responder nextResponder])) {
if ([responder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)responder;
}
}
return nil;
复制代码
} 在cell中 GoodsDetail_ViewController *VC = [GoodsDetail_ViewController new]; [[self getcurrentviewController].navigationController pushViewController:VC animated:YES];
- 已经在界面上都配置好了,代码里面就不需要这些设置了 只需处理点击事件,比如选中第一个,第一个button.selected = YES,其他两个button.selected = NO
- 取出button UIButton * button = [self.view viewWithTag:tag]
5.便利字典类型 用 enumerateKeysAndObjectsUsingBlock NSArray *array = [[NSArray alloc]initWithObjects:@"a",@"b",@"c",@"d",@"e",@"f", nil];
//遍历数组元素
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"obj=%@ idx=%ld",obj,idx);
}];
//如果指定了NSEnumerationConcurrent顺序,那么底层通过GCD来处理并发执行事宜,具体实现可能会用到dispatch group。也就是说,这个会用多线程来并发实现,并不保证按照顺序执行
//NSEnumerationReverse 倒序排列
[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"idx=%ld, id=%@", idx, obj);
//当需要结束循环的时候,调用stop,赋予YES
if (idx ==3) {
*stop = YES;
}
}];
//NSIndexSet类代表一个不可变的独特的无符号整数的集合,称为索引,因为使用它们的方式。这个集合被称为索引集 唯一的,有序的,无符号整数的集合
[NSIndexSet indexSetWithIndex:1];//创建一个索引集合,根据索引值
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,8)];//创建一个索引集合,根据一个NSRange对象
[array enumerateObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,3)] options:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"\n\n\nidx=%ld, id=%@", idx, obj);
}];
复制代码
- self.XXX与_XXX的区别是 self. 调用了setter和getter方法 _XXX 是直接赋值 就是 第一种是调用了创建了赋值的方法
- iOS中UI懒加载 如果用的时候创建 没有就return
- || 是逻辑与 && 是逻辑或
9.设置状态栏的颜色为白色
-(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } - 设置navigationbar的颜色为黑色 self.navigationController.navigationBar.barTintColor = UIColorBlack;
11.类方法和实例方法 工厂方法
类方法不能调用属性 需要用创建实例 调用
类方法里可以创建实例 调用实例
12. 图片不变形
_bottonView.contentMode = UIViewContentModeScaleAspectFit;
- 登录页和 主页面 的切换
原理是更换 window 的rootVC
在APPDelegate 中判断是否登录 登录 调到主页面 没有弹出登录页面 - 创建tableview 用plant headerview 不悬浮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat sectionHeaderHeight = 50; if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0,0); } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); } }
-
https://github.com/dzenbot/DZNEmptyDataSet 空view 站位图 16 . https://github.com/LoveZYForever/HXWeiboPhotoPicker 多图选择第三方
-
关于 UI懒加载 原理是 当view 需要加载的时候再加载 否则 不加载 不用 一下子init出来 设置好view 在添加到view上
-
解决cell 的编辑状态的时候cell 重用导致的 原理是让cell 进去复用池中取数据 给cell加不同的复用标识 这样在取出来的话 还是原来的数据
-
rac 通知传值
-
mutablearry去除重复数据
-
页面的数据 用一个model 来保存 然后赋值
-
https://github.com/ko1o/PYSearch 搜索框
-
pop到指定的页面 原理是 循环navigationcontroller 找到 对应的controller pop到指定controller
for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[GoodsaddAddressController class]]) { GoodsaddAddressController *VC = (GoodsaddAddressController *)controller; [self.navigationController popToViewController:VC animated:YES]; } }
-
iOS取消tableview的footview 和headerview 的粘性 tableview设置style 为group 然后设置高度为0.001 这个是最简单的 亲测 可用
-
iOS 修改 tableview header和footer 的颜色 headerview.contentView.backgroundColor == UIColorWhite;