iOS 常見(jiàn)問(wèn)題集錦(一)

1:AlertView cancle pop后鍵盤(pán)彈出

A push B, B 點(diǎn)返回的時(shí)候彈出AlertView(B中有個(gè)輸入框之類的),點(diǎn)擊取消,pop到A。返回A后鍵盤(pán)會(huì)出現(xiàn),再做動(dòng)畫(huà)返回。
原因:alertview關(guān)閉影響了系統(tǒng)其他的動(dòng)畫(huà)導(dǎo)致。
解決辦法:要么延遲調(diào)用(延遲0.25秒,鍵盤(pán)動(dòng)畫(huà)收回的時(shí)間),在pop;要么自己做一個(gè)alertview。

2:UIWebView占內(nèi)存過(guò)大

WKWebView新特性:
在性能、穩(wěn)定性、功能方面有很大提升(最直觀的體現(xiàn)就是加載網(wǎng)頁(yè)是占用的內(nèi)存,模擬器加載百度與開(kāi)源中國(guó)網(wǎng)站時(shí),WKWebView占用23M,而UIWebView占用85M).

3:如何設(shè)置虛線描邊

 self.border = [CAShapeLayer layer];
 _border.strokeColor = kMainColor.CGColor;
 _border.fillColor = nil;
 _border.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.height / 2].CGPath;
 _border.frame = self.bounds;
 _border.lineWidth = 0.5f;
 _border.lineCap = @"square";
 _border.lineDashPattern = @[@3, @3];

 [self.layer addSublayer:_border];

4:如何獲取光標(biāo)位置

int location = aTextView.selectedRange.location;

5:UIScrollView加載子視圖偏移64的問(wèn)題

在一個(gè)VC里如果第一個(gè)控件是UIScrollView,注意是第一個(gè)控件,就是首先addsubview在VC.view上。接著加到scrollView上的View就會(huì)在Y點(diǎn)上發(fā)生64的偏移(也就是navigationBar的高度44+電池條的高度20)。
這個(gè)在iOS7以后才會(huì)出現(xiàn)。

解決辦法:

self.automaticallyAdjustsScrollViewInsets = false; 

6:自定義leftBarButtonItem右劃返回?zé)o效

關(guān)于右劃返回上一級(jí)自定義leftBarButtonItem后無(wú)法啟用系統(tǒng)自帶的右劃返回可以再設(shè)置以下代碼
self.navigationController.interactivePopGestureRecognizer.delegate = self;

7: 去掉導(dǎo)航欄下邊的黑線

[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

8:忽略警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self performSelector:example.selector];
#pragma clang diagnostic pop

9:UITableView隱藏多余的分隔線

設(shè)置tableViewFooter即可

self.sampTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

10:SVN怎么查看最近log信息

svn log | head -n X
x代表行數(shù)

11:SVN怎么查看指定日期的log信息

svn log -r {2016-4-24}:{2016-4-26} -v
開(kāi)始日期:結(jié)束日期
-v 打印詳細(xì)信息 和svn log --verbose 中 --verbose一樣的效果

12:UIActionSheet代理present UIImagePickerController異常

在UIActionSheetDelegate代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

present UIImagePickerController時(shí)報(bào)警告:

Warning: Attempt to present <UIImagePickerController: 0x> on 
<**Controller: 0x> which is already presenting <UIAlertController: 0xd37b8b0>

這是因?yàn)橐呀?jīng)有actionSheet存在了,不能present新的。
解決:把present代碼換個(gè)代理方法里面實(shí)現(xiàn):

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 

13:關(guān)于const定義常量的問(wèn)題

static NSString const * kUserName = @"Strong";
static const NSString * kUserName = @"Strong";

如上定義這個(gè)kUserName其實(shí)是可以更改的。下面的代碼kUserName才是不可變的

static NSString * const kUserName = @"Strong";

當(dāng)const修飾的是(*****kUserName)的時(shí)候,不可變的是*****kUserName;
星號(hào)*在C語(yǔ)言中表示指針指向符,也就是說(shuō)這個(gè)時(shí)候*****userName指向的內(nèi)存地址中的內(nèi)容不可變,而kUserName這個(gè)指針是可變的。
總結(jié): const 修飾的是他右邊的部分。

14:Xcode的運(yùn)行環(huán)境沒(méi)有模擬器了

原因1:Xcode沒(méi)有下載模擬器;
解決:用command + , 快捷鍵打開(kāi)偏好設(shè)置,選擇downloads選項(xiàng),下載模擬器即可。
原因2:新建的工程默認(rèn)的Deployment Target是8.4,模擬器沒(méi)有8.4或者比8.4更高的了。所以無(wú)法選擇模擬器了;
解決:把模擬器的運(yùn)行環(huán)境往下降就好了。

15: 計(jì)算NSData大小

- (NSString *)getFileSizeByBt:(NSNumber *)fileSize {
    CGFloat size = [fileSize floatValue];
    if (size >= 1024*1024*1024) {
        return [NSString stringWithFormat:@"%.2fG",size/(1024*1024*1024)];
    }else if (size >= 1024*1024) {
        return [NSString stringWithFormat:@"%.2fM",size/(1024*1024)];
    }else{
        return [NSString stringWithFormat:@"%.2fK",size/1024];
    }
}

16:如何清除xcode里面的Provisioning Profiles

終端:

cd ~/Library/MobileDevice/Provisioning Profiles/
rm  *.mobileprovision

手動(dòng) : 資源庫(kù)->MovileDevice->provisioning Profiles->目的文件

deleteProvisioningProfiles.png

17:字符串中去除特殊符號(hào)

NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-*+=_\\|~<>$€^?'@#$%^&*()_+'\""];
NSString *trimmedString = [string stringByTrimmingCharactersInSet:set];

18:app在后臺(tái)或者沒(méi)啟動(dòng)的時(shí)候,收到遠(yuǎn)程通知badge不顯示

app在后臺(tái)和沒(méi)啟動(dòng)的時(shí)候,應(yīng)用圖標(biāo)右上角的數(shù)字圖標(biāo)是根據(jù)遠(yuǎn)程通知里面數(shù)據(jù)來(lái)顯示的,控制的key就是badge,在aps字典中,badge對(duì)應(yīng)的字段,注意,badge對(duì)應(yīng)的字段必須是數(shù)字,不能是字符,如果服務(wù)器傳給APNS的badge是字符型,那app接受到遠(yuǎn)程通知的時(shí)候,就顯示不出來(lái)右上角的數(shù)字了。

19:怎么改變textField的placeholder字體顏色和大小

使用KVC找到placeholderLabel,對(duì)齊屬性賦值

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

20:消除導(dǎo)航條返回鍵帶的title

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
  forBarMetrics:UIBarMetricsDefault];

21:將Navigationbar變成透明而不模糊

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                         forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar .shadowImage = [UIImage new];
self.navigationController.navigationBar .translucent = YES;

22:加載bundle中的圖片

_iconImageView.image = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"UMSocialSDKResourcesNew.bundle/SnsPlatform/UMS_wechat_icon@2x.png"]];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,724評(píng)論 19 139
  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一種新的協(xié)議。它實(shí)...
    香橙柚子閱讀 24,844評(píng)論 8 183
  • 雨,濕了轉(zhuǎn)角的青苔;汗,鹹了書(shū)桌的邊緣;淚,傷了衣角的心窗;憶,惜了心靈的青春。 這年,註定是歡喜的一年,註定是殘...
    guoliC閱讀 305評(píng)論 0 0
  • 我把自己逼進(jìn)了一個(gè)死胡同,初一期中考試如此,于我而言更重要的考編亦是如此,我總是走了一條對(duì)我而言困難的道路,很累卻...
    踏過(guò)昨天閱讀 194評(píng)論 0 0

友情鏈接更多精彩內(nèi)容