簡體   English   中英

在iOS 7.1中進入后台模式時,應用崩潰

[英]App crashes while entering background mode in iOS 7.1

今天,我將Xcode升級到最新版本(版本5.1(5B130a))以支持iOS 7.1。 完成此操作后,我通常會在Xcode中運行我的項目。 然后,應用程序在進入背景mdoe時崩潰。 在升級iOS SDK之前,我沒有更改任何代碼。 該代碼可以在iOS 5.x,6.x,7.0.x中完美運行。

當應用進入后台模式時,它不會執行任何操作,如以下代碼所示:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // do nothing
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

跟蹤崩潰日志后,我發現崩潰點在以下屏幕快照中的突出顯示的行上: 在此處輸入圖片說明

任何想法?

順便說一句,該項目正在使用非ARC機制。 並且視圖控制器由情節提要初始化。

似乎您正在訪問已發布的內容(根據您的崩潰進行猜測)。

啟用僵屍,這會告訴您您是否是誰,以及令人討厭的對象是什么。

產品>方案>編輯方案

然后點擊“運行您的項目>診斷>啟用僵屍對象

然后重新運行並關閉它,看看調試器中的崩潰是否已更改...

  • 轉到“斷點導航器”
  • 左鍵單擊項目導航器底部的“添加新斷點”(左底部)
  • 單擊“添加例外斷點”

現在運行該項目,您將獲得崩潰的確切點。

最后,我知道會發生什么。

我得到一個這樣的表視圖控制器:

@interface UserMenuViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate> {
    ....
}

在以下方法中,我使用[UIButton buttonWithType:]方法在表格視圖單元格中創建一個UIButton組件。 將按鈕插入單元格后,我松開它。 但是我不應該這樣做,因為這是一個錯誤。 因此,當應用程序要進入后台模式時,UIButton對象似乎變得混亂。 在標記發布代碼后,它現在可以正常工作。 ^^

但是我仍然不知道為什么在iOS 5.x,6.x和7.0.x中運行時還可以。 在那些環境中它也應該崩潰。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
if( row == 5 ) {
    BOOL bDidLogin = NO;
    NSString *fileName = bDidLogin? @"btn_logout.png":@"btn_login.png";
    SEL callback = bDidLogin? @selector(doLogout:):@selector(doLogin:);
    UIImage *img = [UIImage imageNamed:fileName];
    UIButton *btn = [Utils generateImgButton:img withHandler:self withCallback:callback withBgColor:[UIColor clearColor]];
    float x = cellWidth - btn.frame.size.width - padding*2;
    float y = cellHeight - btn.frame.size.height - padding*2;
    [Utils moveView:btn toX:x toY:y];
    [cell.contentView addSubview:btn];
    [btn release]; // should not do this!!!!!!!!!!!!!
}
....
}

在Utils.m中:

+ (UIButton *) generateImgButton:(UIImage *)img withHandler:(id)handler withCallback:(SEL)callback
                 withBgColor:(UIColor *)bgColor {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:bgColor];
[button setImage:img forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, img.size.width, img.size.height);
[button addTarget:handler action:callback forControlEvents:UIControlEventTouchUpInside];
return button;
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM