6

menuを備えたデフォルトのマスター/詳細テーブルビューがあります。メニューは機能しますが、「+」ボタンを押してアプリに別のセルを追加すると、何らかの理由で次のエラーが発生します。

キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。

何日も解決策を探した

に追加するとviewDidLoad

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];

エラーは発生しませんが、追加されたセルはストーリーボードで構成されたものではなく、詳細ビュー コントローラーを指していません。

プロトタイプ セルの識別子フィールドが入力されていて、*cellIdentifier と同じであるかどうかを何度も確認しました。

私が知っている限りでは、ここで尋ねられた質問と同じ性質のようです。

時間があれば、私がしたことが間違っている理由、または特定のコードを追加する必要がある理由を説明してください。

要求されたコード (どちらも Xcode 5.0.1 によって追加されたデフォルトのコードです):

// Code to add the button

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;

// Code called when button is pressed:

- (void)insertNewObject:(id)sender
{
    if (!_objects) {
        _objects = [[NSMutableArray alloc] init];
    }
        [_objects insertObject:[NSDate date] atIndex:0];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    NSDate *object = _objects[indexPath.row];
    cell.textLabel.text = [object description];
    return cell;
}

コメントに追加された写真とプロジェクト ファイルもチェックしてください

4

1 に答える 1

2

の次の行を置き換えます[MAAppDelegate application:didFinishLaunching]

UINavigationController *masterViewController = [[UINavigationController alloc] initWithRootViewController:[MAMasterViewController new]];

UINavigationController *masterViewController = (UINavigationController *)self.window.rootViewController;

アプリが に到達するdidFinishLaunchingと、ルート ビュー コントローラーはストーリーボードから既に構成されています (ストーリーボードを見ると、ルート ビュー コントローラーは矢印が指しているコントローラーです)。このプロセスはinitWithCoder:初期化子に依存していることに注意してください。

ではdidFinishLaunching、このビュー コントローラを破棄し、 のインスタンスに置き換えます。このインスタンスは、とTWTSideMenuViewControllerのストーリーボードではない新しいインスタンスで構成しました。考えてみると、特定のストーリーボード要素から構成する必要があることを知る方法はありません。実際には、ストーリーボードからビュー コントローラーをインスタンス化するための API があります: . しかし、それはすでにあなたのために行われているので、あなたはそれをする必要はありません.UINavigationControllerMAMasterViewController[MAMasterViewController new][storyboard instantiateViewControllerWithIdentifier:]

したがって、解決策は簡単です。TWTSideMenuViewController既存のルート View Controller で構成するだけself.window.rootViewControllerです。

于 2013-11-11T01:02:39.537 に答える