2012-02-24 10 views
0

iOS開発を始めたばかりで、タブ1(2番目のタブ)にTableViewControllerを使ってUITabBarControllerを作成するとクラッシュしています。iOS UITabBarController issue

は、ここに私のコードです - AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
diseases = [NSMutableArray arrayWithCapacity:5]; 
     Disease *disease1 = [[Disease alloc] init]; 
     Disease *disease2 = [[Disease alloc] init]; 
     Disease *disease3 = [[Disease alloc] init]; 
     Disease *disease4 = [[Disease alloc] init]; 
     Disease *disease5 = [[Disease alloc] init]; 

     disease1.name = @"disease1"; 
     disease2.name = @"disease2"; 
     disease3.name = @"disease3"; 
     disease4.name = @"disease4"; 
     disease5.name = @"disease5"; 

     [diseases addObject:disease1]; 
     [diseases addObject:disease2]; 
     [diseases addObject:disease3]; 
     [diseases addObject:disease4]; 
     [diseases addObject:disease5]; 


UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 

UINavigationController *navigationController = 
[[tabBarController viewControllers] objectAtIndex:0]; 

FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"NormalBiopsy" bundle:nil]; 
firstViewController = [[tabBarController viewControllers] objectAtIndex:0]; 

DiseaseTableViewController *diseaseTableViewController = [[DiseaseTableViewController alloc] initWithNibName:@"DiseaseTableViewController" bundle:nil]; 
diseaseTableViewController = [[tabBarController viewControllers] objectAtIndex:1]; 

SecondViewController *secondViewController = [[SecondViewController alloc] 
               initWithNibName:@"TestYourSelf" bundle:nil]; 
secondViewController = [[tabBarController viewControllers] objectAtIndex:2]; 

ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"About" bundle:nil]; 
thirdViewController = [[tabBarController viewControllers] objectAtIndex:3]; 

// Override point for customization after application launch. 
return YES; 
} 

これはDiseaseTableViewControllerのテーブルビューで空白のテーブルでUITabBarControllerにつながる - データが読み込まないので。 しかし、私はと

diseaseTableViewController.diseases = diseases; 

アプリのクラッシュを行う場合:

diseaseTableViewController = [[navigationController viewControllers] objectAtIndex:1]; 

原因:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController viewControllers]: unrecognized selector sent to instance 
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-    [UINavigationController setDiseases:]: unrecognized selector sent to instance 

は、だから私はnavigationControllerにdiseaseTableViewControllerを追加しようとしました

私はAppDelegateではなくそのクラスの実装でDiseaseTableViewControllerを実装しようとしましたが、再びUIの空白のテーブルで終了しました。

アイデア?

答えて

0

は私があるとして、元AppDelegateを残し、そして種類の@Zhangが

0

あなたの質問を正しく理解しているかどうかはわかりませんが、基本的には、タブバーのインターフェイスを備えたアプリケーションを作成したいと思っています。

あなたはおそらく、アプリケーション構造のため、このような何かをしたい:だから、その構造

AppDelegate 
| 
| 
|___ UITabBarController 
    | 
    |__ UINavigationController1 
    | | 
    | |__ DiseaseController1 
    | 
    | 
    | 
    |__ UINavigationController2 
    | | 
    | |__ DiseaseController2 
    | 
    | 
    | 
    |__ UINavigationController3 
    | | 
    | |__ DiseaseController3 
    | 
    | 
    | 
    | 
    |__ UINavigationController4 
    | | 
    | |__ DiseaseController4 
    | 
    | 
    | 
    | 
    |__ UINavigationController5 
     | 
     |__ DiseaseController5 

なり、以下:

  1. はAppDelegate
  2. のためのあなたのルートコントローラとしてごUITabBarControllerを作成して設定
  3. UINavigationControllerを作成してUITabBarControllerの各タブとして設定します
  4. 対応するDiseaseViewControllerをeaに追加しますあなたのUINavigationControllerのch

テーブルを扱うときは、テーブルのデータソースと委任を設定する必要があります。自己DiseaseViewControllerを指し

myTable.source = self; 
myTable.delegate = self; 

あなたは、例えば、テーブルを作成しました:これまでDiseaseViewControllerはあなたがあなたのテーブルを作成しますので、どの

は、あなたのような何かをする必要があり

// psuedocode 
@class Disease1 
{ 
    UITableView myTable; 
} 

@property (nonatomic, retain) UITableView myTable; 

@end 

// implementation code 
@implementation Disease1 

-(void)viewDidLoad() 
{ 
    . . . 
    myTable.source = self; 
    myTable.delegate = self; 
    . . . 
} 

@end 
+0

感謝を述べたもののように)(のviewDidLoadでDiseaseController.diseasesのデータを取り込むことによって、これを解決し、私はあなたが少し逃したと思います私の貧しい説明からの質問! DiseaseTableViewController(病気の配列を持つ)のみがタブ1(第2タブ)にあり、残りは異なるビューコントローラです。ですから、私はテーブルのエントリとして5つの病気があるでしょう(これは意味がありますか、または私はDiseaseTableViewControllerまたはそのビューのviewDidLoadメソッドでそれを行うことができますか?)。私はすでにDiseasTableViewControllerを指しているUiNavigationControllerを持っていますが、その選択エラー – oliveromahony

関連する問題