xcode5で画面遷移時にエラー

  •  

 

xcodeでpushして新しく作成した画面に遷移する際に、よく分からん感じになってエラーになる現象。
ナビゲーションバーで前の画面に戻ろうとすると真っ黒になって落ちます。

nested push animation can result in corrupted navigation barというエラーも出てます。
5分程悩んだので。

エラーは以下。

2014-02-15 11:24:27.012 Woodsmall[15070:60b] nested push animation can result in corrupted navigation bar
2014-02-15 11:24:27.414 Woodsmall[15070:60b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

これ、UITableViewのCellをタップすると別画面に遷移するんですが、結論から言うと12行目の「break;」を書き忘れていただけ!
これたまにやります。

// セルタップ時
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; // 選択状態の解除
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                // 画面遷移
                ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
                [self.navigationController pushViewController:viewController animated:YES];
                break;
            }
            case 1:
            {
                // 画面遷移

break;が無いので、case 0で画面遷移して、更にcase 1でもう1つの画面に遷移。
分かってしまえば、エラー内容も納得なんですが。

あと、Androidもそうだけど、他の人が作ったアプリを触ってると変な動作する時があって。
それも大体これです。

あとはxcode(Objective-C)の場合、switch文のcaseは以下ではなくて。

switch (indexPath.row) {
    case 0:
        // 処理
        break;
    case 1:
        // 処理
        break;
}

こっちが正しい。

switch (indexPath.row) {
    case 0:
    {
        // 処理
        break;
    }
    case 1:
    {
        // 処理
        break;
    }
}

これも、xcodeで開発しはじめた頃はハマりました。

株式会社woodsmallの小林でした。
https://woodsmall.co.jp/

関連記事

コメント

この記事へのコメントはありません。

TOP