昨天去一家公司面試,面試官問了我在項目開發中遇到過哪些問題,是什麼引起的,怎樣解決的? 當時由于有點小緊張隻說出了一兩點,現在就來好好總結一下.
問題:
1.兩表關聯
所謂的兩表關聯就是有左右兩個表格,左邊的表格由二個分類構成,大分類用HeaderView 展示,小分類用cell 展示;右邊的表格負責展示分類下的商品. 通過左邊的分類點選展示對應右邊表格的商品好處理,通過tableView的didSelectRowAtIndexPath 方法就能解決,可關鍵是滑動右邊的表格要對應選中左邊的分類,怎麼處理???
還是tableView 的代理方法
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section {
if (_isRelate) {
NSInteger topCellSection = [[[tableView indexPathsForVisibleRows] firstObject] section]; //右邊的section
}
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if (_isRelate) {
NSInteger topCellSection = [[[tableView indexPathsForVisibleRows] firstObject] section]; //右邊的section
if (tableView == _rightTableView) { //根據右邊表格的section 查找左邊對應的row 或section
}
}
}
#pragma mark - tableView 是繼承scrollView 的
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
_isRelate = YES;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (tableView.tag==0) return 40;
else return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if (tableView.tag==0) return 0;
else return 0.01;
}
注:右邊滑動表格的 heightForHeaderInSection 以及 heightForFooterInSection 必須>0 使用才有效果
這是參考的gitHub 上的代碼實作的,如需看源碼,去gitHub搜尋兩表關聯即可. 如果有更好的處理辦法,歡迎補充!
2.關于UITabBar的隐藏
剛開始一直是使用 [self.tabBarController.tabBar setHidden:NO]; 對tabBar 進行隐藏的,這個代碼在一般情況确實能實作隐藏的效果,但是什麼情況下會有問題呢?
當控件(比如button)靠近螢幕底部的時候,無法觸發事件,這個問題糾結了好久,也請教了許多前輩,後來我也上網差了些資料,終于,找到原因了. 就是tabBar 的隐藏問題導緻的.雖然tabBar欄被隐藏了,但在隐藏的區域會成為一片空白區,無法被其他視圖使用。這也就是為何button不響應時間的原因了.
解決辦法:self.hidesBottomBarWhenPushed = YES; (但是要注意使用的時機,應該在視圖push 前就設定隐藏,在pop 前設定為NO)
3.關于鍵盤遮擋輸入框的問題
這個問題有兩種情況,1種是輸入框在self.view 上 另外一種是輸入框在self.tableView 上.
如果是第一種情況,可以去看一下我第一篇博 http://www.cnblogs.com/Cyan-zoey/p/5133167.html
如果是第二種情況:
_oY=_rightTableView.frame.size.height;//記錄初始化的時候tableView 的高度
//鍵盤出現的時候
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect initialFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect convertedFrame = [self.view convertRect:initialFrame fromView:nil];
CGRect tvFrame = _rightTableView.frame;
tvFrame.size.height = convertedFrame.origin.y;
_rightTableView.frame = tvFrame;
}
//隐藏鍵盤
- (void)keyboardWillHide:(NSNotification *)notification {
CGRect tvFrame = _rightTableView.frame;
tvFrame.size.height =_oY;
_rightTableView.frame = tvFrame;
}
推薦使用第三方: IQKeyboardManager
4.手勢沖突
a.UIWebView 嵌套UIScrollView
因為webView的内容是從網絡加載的H5的頁面,放入scrollView 裡面造成手勢沖突,從第一個頁面滑動到webView所在頁面的時候,就無法滑回去了,試了很多種辦法都沒解決. 後來去掉了UIScrollView. 如果有解決辦法的,望賜教! (後來試了下webView中放其他的網頁,發現并沒有産生這個問題,是以可能是嵌入的網頁做了什麼處理,導緻出現了這個情況)
b.tableview上添加點按手勢與cell 點選事件沖突。
我在tableView 上添加了點按手勢,在方法中删除了彈出層
[_tableView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tableTap)];
tap.delegate=self;
[_tableView addGestureRecognizer:tap];
#pragma mark ---點選tableView 中的空白部分删除彈出層
- (void)tableTap{
[_typeView removeFromSuperview];
_isEdit=NO; //在彈出層顯示的時候設定為Yes ,消失的時候設定為NO
}
解決辦法:實作手勢的代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// 輸出點選的view的類名
//NSLog(@"%@", NSStringFromClass([touch.view class]));
if (_isEdit==YES) { //不攔截
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return YES;
}
}else{
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
}
// 若為UITableViewCellContentView(即點選了tableViewCell),則不截獲Touch事件
return YES;
}
c.scrollView上添加手勢不響應
http://blog.csdn.net/zouxianm/article/details/48194657
補充:事件沖突
self.view 上添加tableView ,在self.view 整體往上移動的時候,tableView 的行點選事件失效,任何手勢都不響應。
解決辦法:将tableView 添加到到window 上。
5.彈出層與删除層
5.1 彈出可移動的view(類似于windows上面可移動的彈框)
//先建立手勢
UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(doHandlePanAction:)];
[self.bigView addGestureRecognizer:panGestureRecognizer];
//拖動處理
- (void) doHandlePanAction:(UIPanGestureRecognizer *)paramSender{
CGPoint point = [paramSender translationInView:self.view];
NSLog(@"X:%f;Y:%f",point.x,point.y);
paramSender.view.center = CGPointMake(paramSender.view.center.x + point.x, paramSender.view.center.y + point.y);
[paramSender setTranslation:CGPointMake(0, 0) inView:self.view];
}
5.2 點選彈出層之外的地方,删除彈出層。
a. 彈出層加在self.view 上面
#pragma mark ---觸摸事件---判斷目前點是否在某個範圍内
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint t=[[touches anyObject] locationInView:self.bigView]; //bigView為彈出層
if (!CGRectContainsPoint(_bigView.frame, point)) //不在某個範圍内
{
[self.bigView removeFromSuperview];//删除
}
}
b.彈出層加在AppDelegate的window上面。
//先注冊點選手勢
[_bigView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didmissTK:)];
[_bigView addGestureRecognizer:tap];
//實作方法
- (void)didmissTK:(UIGestureRecognizer *)gest{
CGPoint point = [gest locationInView:_bigView];
if (!CGRectContainsPoint(_bigView.frame, point, point)){
[self.bigView removeFromSuperview];
}
}
原因: 加在self.view 上面視圖的不包括頂部的導航欄,要想包含導航欄就隻能加在window 上面。 加在window上面就相當于在self.view 上覆寫了一層,是以 touchesBegan方法就無法響應,是以隻能在window的彈出層上加手勢去删除彈出層。
6.點選按鈕不響應
a. 看一下該按鈕是否是在UIImageView 上面,如果在,看一下是否把互動打開[_bigView setUserInteractionEnabled:YES];
b. 列印一下按鈕的frame以及按鈕父視圖的frame,看一下按鈕是否在父視圖的範圍内,如果不在,那麼按鈕不響應。在父視圖的frame 内不響應,檢視frame 是否不在螢幕内(self.view ),如果父視圖的self.view.frame.original 為負,不響應事件。
c. 看一下按鈕所在視圖之上是否有覆寫層。如果有,移除覆寫層即可。
還有就是如果給按鈕設定圓角或者邊框顔色(與layer有關的)沒有反應,記得設定 [btn.layer setMasksToBounds:YES];
7. Cell背景色覆寫按鈕的顔色
cell預設選中行的顔色是灰色的,如果cell上有按鈕等控件,會讓自身的顔色被灰色覆寫
解決方法: 在自定義的cell中實作如下兩個方法即可:
-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
被覆寫的控件名.backgroundColor = UIColor.redColor;
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
被覆寫的控件名.backgroundColor = UIColor.redColor;
}
暫時隻能想到這麼多啦,再想到了新的會及時補充的.
現在來總結一下項目中使用到的SDK
1.騰訊地圖SDK :進行地位,以及地圖展示
2.SDWebImage:圖檔處理
實作過程:a: 如果設定了placeholderImage(占位圖)就先展示占位圖
b: SDImageCache 從記憶體中查找緩存的圖檔-》 找到了圖檔 , SDImageCacheDelegate 回調 到UIImageView+WebCache 等前端展示圖檔
-》 沒找到圖檔 則去硬碟中查找-》找到了,SDImageCacheDelegate回調展示圖檔
-》沒找到 ,使用SDWebImageManager下載下傳圖檔
c:替換占位圖
詳情請參考
3.MJRefersh:上下拉重新整理
4.MBProgressHUD:提示框
5.AFNetWorking: 網絡請求
(1)組成:(封裝自NSURLSession)
NSURLSession (AFURLSessionManager/AFHTTPSessionManager)----網絡通信子產品(核心子產品)
Security(AFSecurityPolicy)----網絡通訊安全政策子產品
Reachability(AFNetworkReachabilityManager)----網絡狀态監聽子產品
Serialization(AFURLResponseSerializationAFURLRequestSerialization/)---網絡通信資訊序列化、反序列化子產品
UIKit ----UIKit庫
6.友盟應用統計錯誤分析
7.ping++:第三方支付
8.ZBarSDK:掃二維碼/條形碼 詳細請見:http://www.cnblogs.com/Cyan-zoey/p/6121909.html
9.GtSdk :消息推送 詳情請見:http://www.cnblogs.com/Cyan-zoey/archive/2016/04/28.html
10.融雲即時通訊,內建客服.
轉載于:https://www.cnblogs.com/Cyan-zoey/p/5741893.html