2

最初の UITableView にワークアウト名を表示し、2 番目の UITableView にエクササイズを表示するワークアウト アプリのドキュメントの SimpleDrillDown アプリの例に従いました。

私のアプリは Dropbox にあります: http://db.tt/V0EhVcAG

私はストーリーボードを使用し、プロトタイプセルを持っていますが、シミュレーターにロードすると、最初の UITableView をクリックして詳細 UITableView に移動できません。開示インジケーターのシェブロンが読み込まれません。アプリは正常にビルドされ、正式なエラーはありません。

私のテーブルビューはナビゲーションコントローラーにあり、セグエとプロトタイプのセルはすべてストーリーボードでそれに応じて名前が付けられています。

SpitfireViewController.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataController countOfList];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"WorkoutCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    Workout *workoutAtIndex = [dataController objectInListAtIndex:indexPath.row];
    cell.textLabel.text = workoutAtIndex.title;

    return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showExercises"]) {
        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];

        DetailViewController *detailViewController = [segue destinationViewController];

        detailViewController.workout = [dataController objectInListAtIndex:selectedRowIndex.row];
    }
}

DetailViewController.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [workout.exercises count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ExerciseCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [workout.exercises objectAtIndex:indexPath.row];
    return cell;
}

AppDelegate.h

#import <UIKit/UIKit.h>
@class DataController;
@class SpitfireViewController;

@interface SpitfireAppDelegate : UIResponder <UIApplicationDelegate>
{
    UIWindow *window;
    SpitfireViewController *spitfireViewController;
    DataController *dataController;
}

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#import "SpitfireAppDelegate.h"
#import "SpitfireViewController.h"
#import "DataController.h"

@implementation SpitfireAppDelegate
@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    spitfireViewController = [[SpitfireViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:spitfireViewController];

    DataController *controller = [[DataController alloc] init];
    spitfireViewController.dataController = controller;

    [window addSubview:[navController view]];
    [self.window makeKeyAndVisible];

    return YES;
}

@end

マイストーリーボード SpitfireViewController (ルート) 詳細ViewController

4

4 に答える 4

1

ストーリーボードを使用するときは、通常、[情報] タブの [プロジェクト設定] でストーリーボード ファイル名を設定します。そこでストーリーボードを選択したら、基本的にメソッドのreturn YES部分を除いてすべてを削除できます。application:didFinishLaunchingWithOptions:ストーリーボードですべて処理されます。

編集:

ストーリーボードを設定する場所は次のとおりです。

メインストーリーボードを設定する

また、View Controller が初期 View Controller として設定されていることを確認してください。

初期ビュー コントローラを設定する

于 2013-04-24T02:32:11.560 に答える
1

これがあなたの問題だと思います:

    spitfireViewController = [[SpitfireViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:spitfireViewController];

    DataController *controller = [[DataController alloc] init];
    spitfireViewController.dataController = controller;

ここで作成する spitfireViewController は、ストーリーボードのものではなく、新しいものです。ストーリーボードで作成したナビゲーション コントローラーに既に spitfireViewController が埋め込まれているため、このコードはすべて削除する必要があります。viewDidLoad メソッドで spitfireViewController のデータ コントローラーを設定する必要があります。

    DataController *controller = [[DataController alloc] init];
    self.dataController = controller;
于 2013-04-24T03:54:18.663 に答える
-1

「didSelectRowAtIndexPath」メソッドはどこにありますか?

それを入力してから [self performSegueWithIdentifier:] をトリガーして、テーブル セルのデータを送信者として使用してセグエをトリガーすることをお勧めします。

于 2013-04-24T02:49:43.207 に答える