1. 程式人生 > >Xcode IOS開發錯誤彙總

Xcode IOS開發錯誤彙總

【錯誤資訊】

真機除錯時出現如下錯誤:

Code Signing Error

Signing for "*****" requires a development team.Select a development team in the project editor.

Code signing is required for product for product type 'Application' in SDK 'IOS 11.0'

原因及解決辦法:


【錯誤資訊】
真機除錯,彈出對話方塊如下:Could not launch "*****"Verify the Developer App certificate for your account

is  trusted on your device. Open Settings on "**"的iphone and

navigate to General -> Device Management, then select your Developer App certificate to trust it.

原因及解決辦法:
開啟手機設定->通用->裝置管理,找到編輯工程時的ID資料,點選信任“****”即可。
【錯誤資訊】

2017-11-01 22:41:40.360911+0800 01-切換文字顏色-第一個iOS程式[1119:49204] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Test01ViewController 0x7f88f3e08250> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'

原因及解決辦法:
介面View有錯誤連線沒有對應

【錯誤資訊】

網上的開源專案下載下來真機除錯

Code Signing Error: Failed to create provisioning profile. The app ID "com.cloudling.Masonry-iOS-Examples" cannot be registered to your development team. Change your bundle identifier to a unique string to try again.

Code Signing Error: No profiles for 'com.cloudling.Masonry-iOS-Examples' were found:Xcode couldn't find any iOS App Development provisioning profiles matching 'com.cloudling.Masonry-iOS-Examples'.

Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.1'


【錯誤資訊】
真機除錯執行時,
development cannot be enabled while your device is locked.
please unlock your device and reattach.(0xE80000E2).

分析原因:由於第一次連線MAC時,在裝置上點選了"不信任"選項,所以XCode 8不能訪問手機,所以才出現這個問題.。

解決辦法:Apple官網的解釋:https://support.apple.com/en-us/HT202778

技術分享

點選 設定 --> 通用 --> 重置 --> 重置位置和隱私 ,然後關閉xcode 8, 拔掉資料線,重啟xocde 8開啟專案, 重新插上資料線,此時手機上會顯示mac與手機裝置的連線訪問許可權,選擇“信任”即可。

【錯誤資訊】在使用了pods之後首次編譯載入時會出現錯誤 你的Pods存放目錄/Pods/Target Support Files/Pods/Pods-resources.sh: Permission denied原因及解決辦法:
該錯誤是由訪問許可權引起,解決方案是
進入Pods/Target Support Files/Pods/ 目錄以後,執行以下命令即可
chmod a+x Pods-Masonry iOS Examples-resources.sh

【錯誤資訊】

chmod: iOS: No such file or directory

*如何Mac終端中進入含空格檔名的資料夾?

chmod a+x Pods-Masonry" "iOS" "Examples-resources.sh;
或者

chmod a+x Pods-Masonry\ iOS\ Examples-resources.sh;

【錯誤資訊】
真機除錯,彈出對話方塊如下:Development cannot be enabled while your device is locked.Please unlock your device and reattach. (0xE80000E2).

點選 設定 --> 通用 --> 重置 --> 重置位置和隱私 ,然後關閉xcode 8, 拔掉資料線,重啟xocde 8開啟專案, 重新插上資料線,此時手機上會顯示mac與手機裝置的連線訪問許可權,選擇“信任”即可。
【錯誤資訊】TableView類方法cellForRowAtIndexPath,執行之後cell為nill

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:ID];

cell.textLabel.text = [NSStringstringWithFormat:@"cell - %zd", indexPath.row];

return cell;

【錯誤資訊】

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7fd1ad0a0000; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000255810>; layer = <CALayer: 0x6000004287a0>; contentOffset: {0, -64}; contentSize: {375, 220}; adjustedContentInset: {64, 0, 0, 0}>) failed to obtain a cell from its dataSource (<_UIFilteredDataSource: 0x600000256a70>)'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7fd1ad0a0000; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000255810>; layer = <CALayer: 0x6000004287a0>; contentOffset: {0, -64}; contentSize: {375, 220}; adjustedContentInset: {64, 0, 0, 0}>) failed to obtain a cell from its dataSource (<_UIFilteredDataSource: 0x600000256a70>)'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7fd1ad0a0000; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000255810>; layer = <CALayer: 0x6000004287a0>; contentOffset: {0, -64}; contentSize: {375, 220}; adjustedContentInset: {64, 0, 0, 0}>) failed to obtain a cell from its dataSource (<_UIFilteredDataSource: 0x600000256a70>)'

原因及解決辦法:
因為本想獲取Storyboard中已經定義好的UITableViewCell,但是由於跳轉到這個Controller是如下生成的:
FBQuestionSaveViewController *save = [[FBQuestionSaveViewController alloc] init];
// 導航控制器呼叫push,跳轉到儲存問卷的介面
[self.navigationController pushViewController:save animated:YES];
正確的應該用如下方式建立storyboard已經生成好的viewcontroller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITableViewController *save = [storyboard instantiateViewControllerWithIdentifier:@"QuestionSaveViewController"];
[self.navigationController pushViewController:save animated:YES];
【iOS開發之TableView實現完整的分割線】
解決辦法,首先在viewDidLoad方法加入以下程式碼:
if([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
// 如果tableView響應了setSeparatorInset: 這個方法,我們就將tableView分割線的內邊距設為0.
  [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
// 如果tableView響應了setLayoutMargins: 這個方法,我們就將tableView分割線的間距距設為0.
  [self.tableView setLayoutMargins:UIEdgeInsetsZero];
}

然後在UITableView的代理方法中加入以下程式碼
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// 這兩句的含義跟上面兩句程式碼相同,就不做解釋了
 if([cell respondsToSelector:@selector(setSeparatorInset:)]) {
   [cell setSeparatorInset:UIEdgeInsetsZero];
  }
 if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
   [cell setLayoutMargins:UIEdgeInsetsZero];
  }
}
原因及解決辦法:真機除錯時,出現免費應用程式除錯最大限度問題,一臺手機最多隻允許3個除錯APPApp installation failed
The maximum number of apps for free development profiles has been reached.
【錯誤資訊】
errors:The operation couldn’t be completed. Unable to log in with account 'myappleid'. An unexpected failure occurred while logging in (Underlying error code 1100).

原因及解決辦法:

賬號被登出,需要重新登入一下

 I had to go to "Preferences" -> "Accounts", where it turned out my Apple ID had timed-out. After logging-in there, and then restarting Xcode, my profile was automatically "repaired", and all is now well.
【錯誤資訊】
“The resource could not be loaded because the App Transport Security policy requires the use of a secure connection”
原因及解決辦法:
iOS9引入了新特性App Transport Security (ATS)
新特性要求App內訪問的網路必須使用HTTPS協議。
  1. 在Info.plist中新增NSAppTransportSecurity型別Dictionary
  2. NSAppTransportSecurity下新增NSAllowsArbitraryLoads型別Boolean,值設為YES
最新的Xcode如下:

【錯誤資訊】

IOS警告函式頭 used as the name of the previous parameter rather than as part of the selector

原因及解決辦法:

多為傳入多個變數沒有空格引起,在第二變數的冒號前面加個空格既可以解決。

【錯誤資訊】

使用真機Iphone5s除錯時,在UIView上面新增UIScrollView,並在UIScrollView上動態新增控制元件,但是出現第一次顯示的時候控制元件會出現被截掉了顯示不全的問題,佈局的右寬度用的是UIScrollView寬度

原因及解決辦法:

//始終是320

//CGFloat l = [[UIScreen mainScreen] bounds].size.width;

//第一次是600,後面一直是320

//CGFloat m = self.view.frame.size.width;

//第一次是375,後面一直是320

//CGFloat t = self.scrollview.frame.size.width;

如上所述,使用UIScrollView寬度會出現變化的問題,使用[[UIScreen mainScreen] bounds]可以解決