有些很簡單的就隨便看看了艘包,我這也是遇到了就記下來
1.iOS開發(fā)加載圖片·imageNamed
和imageWithContentsOfFile
的區(qū)別
分析:
[UIImage imageNamed:@"placeHolder"],imageNamed只適合用于小尺寸圖片的讀取,或重復(fù)使用一張圖片的時(shí)候,而當(dāng)加載一些比較大的圖片文件的時(shí)候我們應(yīng)當(dāng)盡量避免使用這個(gè)方法.
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
當(dāng)有些圖片在應(yīng)用中只使用比較少的次數(shù)的毛萌,就可以用這樣的方式,相比imageNamed會降低內(nèi)存消耗,避免一些內(nèi)存問題.
2.插入數(shù)組元素
insertObject: atIndex:
[array count]-1; 添加到最后一位
例:
NSArray *arr = @[@"A",@"B",@"C",@"D"];
NSMutableArray *array = [arr mutableCopy];
NSInteger arrCount = array.count;
[array insertObject:@"TheLast" atIndex:arrCount - 1];
3.解決觸控點(diǎn)擊事件和手勢的沖突
一、使用場景:
- 在項(xiàng)目實(shí)際過程中滞磺,經(jīng)常需要在
UITableView
,UIScrollView
等上添加手勢來取消鍵盤響應(yīng),但是UIScrollView
的機(jī)制是接收觸摸事件莱褒,但是會讓手勢暫停一段時(shí)間time-off
,會將手勢截留一段時(shí)間击困,使用一個(gè)定時(shí)器來監(jiān)聽自身坐標(biāo)值是否有所改變,如果坐標(biāo)值改變了广凸,說明滑動(dòng)了阅茶,那么就會取消tracking events
發(fā)送給subViews
蛛枚;相反如果坐標(biāo)值未發(fā)生改變,那么就會將tracking events
發(fā)送給子視圖脸哀。 - 如果在視圖上添加了手勢蹦浦,那么明顯就會有沖突,還好企蹭,蘋果有api幫助我們解決這些問題白筹,實(shí)現(xiàn)這下面代理方法,可以解決觸控點(diǎn)擊事件和手勢的沖突谅摄,包括
UITexFiled
,UITableView
等等控件單擊事件不響應(yīng)問題徒河。
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UITextField class]]){
return NO;
}
// 若為UITableViewCellContentView(即點(diǎn)擊了tableViewCell),則不截獲Touch事件
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}
tap.cancelsTouchesInView = YES;//是否取消點(diǎn)擊處的其他action
4.設(shè)置button上字體的位置
button.titleLabel.textAlignment = NSTextAlignmentLeft; 這句無效
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
5.清除環(huán)信所有聊天記錄
NSArray *conversations = [[EMClient sharedClient].chatManager loadAllConversationsFromDB];
for (EMConversation *con inconversations) {
[condeleteAllMessages];
}
6.CRASH: -[NSNull length]: unrecognized selector sent to instance以及-[NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0
的解決方法
7. 修改環(huán)信消息列表的昵稱
-
EaseConversationCell
中的- (void)setModel:(id<IConversationModel>)model
方法里獲取服務(wù)器中聊天對象的昵稱.
8.在cellForRowAtIndexPath
代理方法里面添加以下代碼解決cell的分割線不置頂問題
if ([cell respondsToSelector:@selector (setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
9.UICollectionView
不能滑動(dòng)問題
_mainCollection.alwaysBounceVertical = YES;
10.環(huán)信聊天修改用戶頭像圓角度
11.實(shí)現(xiàn)公告跑馬燈效果
一送漠、上下滾動(dòng)
導(dǎo)入#import “HRAdView.h"
@property (nonatomic, strong) HRAdView *adView; // 公告欄
// 公告欄
_adView = [[HRAdView alloc] initWithTitles:[_dataDict[@"news"] valueForKey:@"title"]];
_adView.backgroundColor = [UIColor whiteColor];
_adView.frame = CGRectMake(110, 0, main_Width- 120, 47);
_adView.textAlignment = NSTextAlignmentLeft;
_adView.labelFont = kGetSystemFont(16);
_adView.color = GkColor(51, 51, 51);
_adView.isHaveTouchEvent = YES;
_adView.time= 2.0f;
_adView.edgeInsets = UIEdgeInsetsMake(8, 8,8, 10);
[_dybamicView addSubview:_adView];
二顽照、水平滾動(dòng)
1.導(dǎo)入#import “YFRollingLabel.h”
@property (nonatomic, strong) YFRollingLabel *label1;
2.實(shí)現(xiàn)下面方法:
NSArray *arr = [_dataDict[@"news"] valueForKey:@"title"];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(110, 0, main_Width- 120, 47)];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1000);
[_dybamicView addSubview:scrollView];
_label1 = [[YFRollingLabel alloc] initWithFrame:CGRectMake(0, 0, scrollView.frame.size.width, 47) textArray:arr font:kGetSystemFont(16)textColor:GkColor(51, 51, 51)];
[scrollViewaddSubview:_label1];
_label1.speed= 1;
[_label1 setOrientation:RollingOrientationLeft];
[_label1 setInternalWidth:_label1.frame.size.width / 3];
12.在View里面實(shí)現(xiàn)頁面跳轉(zhuǎn)
13.禁止UITableView的header懸停
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
if (scrollView == self.mainTableView){
UITableView *tableview = (UITableView*)scrollView;
CGFloat sectionHeaderHeight = 64;
CGFloat sectionFooterHeight = 44;
CGFloat offsetY = tableview.contentOffset.y;
if(offsetY >= 0 && offsetY <= sectionHeaderHeight){
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height
- sectionFooterHeight){
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height){
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height
- sectionFooterHeight), 0);
}
}
}
14.UIWebView自適應(yīng)寬高
15.返回到指定控制器<[2]是本控制器是第幾級就是幾>
UIViewController *viewCtl = self.navigationController.viewControllers[2];
[self.navigationController popToViewController:viewCtl animated:YES];
16.讓所有子控件無法響應(yīng)交互
17.使用WKWebView適應(yīng)屏幕尺寸
18.如何查看App在AppStore中的地址
https://itunes.apple.com/cn/app/id1********2?mt=8,將id和闽寡?之間的數(shù)字改成App信息里面的App ID<這個(gè)是蘋果自動(dòng)生成的>
19.多個(gè)button可選唯一性
20.隱藏導(dǎo)航欄下面的線條
21.定時(shí)請求
22.計(jì)算購物車總價(jià)
23.在AppDelegate
里面顯示UIAlertController
24.如何在代碼中判斷真機(jī)還是模擬器
25.0x8badf00d表示什么
26.Masonry
mas_equalTo和equalTo
默認(rèn)情況下
mas_equalTo有自動(dòng)包裝功能代兵,比如自動(dòng)將20包裝為@20
equalTo沒有自動(dòng)包裝功能
如果添加了下面的宏,那么mas_equalTo和equalTo就沒有區(qū)別
#define MAS_SHORTHAND_GLOBALS
注意:這個(gè)宏一定要添加到#import "Masonry.h"前面
mas_width和width
默認(rèn)情況下
width是make對象的一個(gè)屬性爷狈,用來添加寬度約束用的植影,表示對寬度進(jìn)行約束
mas_width是一個(gè)屬性值,用來當(dāng)做equalTo的參數(shù)涎永,表示某個(gè)控件的寬度屬性
如果添加了下面的宏思币,mas_width也可以寫成width
#define MAS_SHORTHAND
mas_height、mas_centerX以此類推
27.使用Application Loader
提交ipa
報(bào)錯(cuò)No suitable application records were found. Verify your bundle identifier 'com.scxee.HairdressingDIY' is correct.
解決辦法:在itunes Connect里創(chuàng)建一個(gè)新應(yīng)用就可以了羡微。
28.關(guān)于使用UITableView
出現(xiàn)的關(guān)于** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
問題谷饿。
解決方法:實(shí)現(xiàn)- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
代理方法.
29.關(guān)于使用UITableView
出現(xiàn)的*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:
問題。
解決方法:在 storyBoard
中設(shè)置的 cell 不用在控制器中注冊妈倔。
30.關(guān)于使用UITableView
出現(xiàn)的Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x6000035df220> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key headerLabel.'
問題博投。
解決方法:把約束刪除重現(xiàn)連。
31.關(guān)于使用UITableView
出現(xiàn)的*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
問題盯蝴。
解決方法:控制器中如果是 storyboard
拖的靜態(tài) cell毅哗,在控制器中就不要實(shí)現(xiàn)- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
和- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
這兩個(gè)代理方法。
32.點(diǎn)擊 UITextField
禁止鍵盤彈出结洼。
self.xxxTF.inputView = [[UIView alloc] initWithFrame:CGRectZero];
33.應(yīng)用內(nèi)調(diào)起微信黎做。
屏幕快照 2018-10-29 下午5.49.47.png
屏幕快照 2018-10-29 下午5.49.57.png
NSURL *url = [NSURL URLWithString:@"weixin://"];
BOOL hadInstalledWeixin = [[UIApplication sharedApplication] canOpenURL:url];
if (hadInstalledWeixin) {
// 安裝了此 App
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
//設(shè)備系統(tǒng)為IOS 10.0或者以上的
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else{
//設(shè)備系統(tǒng)為IOS 10.0以下的
[[UIApplication sharedApplication] openURL:url];
}
}else{
[OMGToast showWithText:@"未安裝微信!"];
}