2017.09.27
- 設(shè)置button中圖片的位置用
_leftbtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
這是設(shè)置了title相對于左邊平移了20
2017.9.29 - 有時候需要獲取cell的button的點擊事件 然后調(diào)到另一個頁面
方案一: 寫block函數(shù) 然后再在父viewcontroller里調(diào)用block 如果cell多的話 代碼就會很多 pass掉
方案二:在cell中獲取父視圖的viewcontroller 然后獲取navigationcontroller 進行跳轉(zhuǎn) 這樣cell復(fù)用 中寫跳轉(zhuǎn) 省下很多代碼
我們創(chuàng)建一個 category 擴展里寫自己然后直接調(diào)用方法 話不多少 上碼
在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];
- 已經(jīng)在界面上都配置好了弦悉,代碼里面就不需要這些設(shè)置了
只需處理點擊事件摊唇,比如選中第一個愕乎,第一個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];
//遍歷數(shù)組元素
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"obj=%@ idx=%ld",obj,idx);
}];
//如果指定了NSEnumerationConcurrent順序跷车,那么底層通過GCD來處理并發(fā)執(zhí)行事宜,具體實現(xiàn)可能會用到dispatch group唁毒。也就是說蘑辑,這個會用多線程來并發(fā)實現(xiàn),并不保證按照順序執(zhí)行
//NSEnumerationReverse 倒序排列
[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"idx=%ld, id=%@", idx, obj);
//當需要結(jié)束循環(huán)的時候,調(diào)用stop,賦予YES
if (idx ==3) {
*stop = YES;
}
}];
//NSIndexSet類代表一個不可變的獨特的無符號整數(shù)的集合,稱為索引,因為使用它們的方式浇冰。這個集合被稱為索引集 唯一的贬媒,有序的,無符號整數(shù)的集合
[NSIndexSet indexSetWithIndex:1];//創(chuàng)建一個索引集合肘习,根據(jù)索引值
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,8)];//創(chuàng)建一個索引集合际乘,根據(jù)一個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的區(qū)別是 self. 調(diào)用了setter和getter方法 _XXX 是直接賦值 就是 第一種是調(diào)用了創(chuàng)建了賦值的方法
- iOS中UI懶加載 如果用的時候創(chuàng)建 沒有就return
- || 是邏輯與 && 是邏輯或
9.設(shè)置狀態(tài)欄的顏色為白色
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
} - 設(shè)置navigationbar的顏色為黑色
self.navigationController.navigationBar.barTintColor = UIColorBlack;
11.類方法和實例方法 工廠方法
類方法不能調(diào)用屬性 需要用創(chuàng)建實例 調(diào)用
類方法里可以創(chuàng)建實例 調(diào)用實例
圖片不變形
_bottonView.contentMode = UIViewContentModeScaleAspectFit;登錄頁和 主頁面 的切換
原理是更換 window 的rootVC
在APPDelegate 中判斷是否登錄 登錄 調(diào)到主頁面 沒有彈出登錄頁面創(chuàng)建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 多圖選擇第三方關(guān)于 UI懶加載 原理是 當view 需要加載的時候再加載 否則 不加載 不用 一下子init出來 設(shè)置好view 在添加到view上
解決cell 的編輯狀態(tài)的時候cell 重用導(dǎo)致的 原理是讓cell 進去復(fù)用池中取數(shù)據(jù) 給cell加不同的復(fù)用標識 這樣在取出來的話 還是原來的數(shù)據(jù)
rac 通知傳值
mutablearry去除重復(fù)數(shù)據(jù)
頁面的數(shù)據(jù) 用一個model 來保存 然后賦值
pop到指定的頁面 原理是 循環(huán)navigationcontroller 找到 對應(yīng)的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設(shè)置style 為group 然后設(shè)置高度為0.001 這個是最簡單的 親測 可用