剛開始iOS開發時,我得到了在選項卡1(第二個選項卡)中使用TableViewController創建UITabBarController時的崩潰。iOS UITabBarController問題
這裏是我的代碼 - 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的TableView中空白表的UITabBarController - 因爲填充任何數據。 但是,如果我做
diseaseTableViewController.diseases = diseases;
應用程序崩潰與:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [UINavigationController setDiseases:]: unrecognized selector sent to instance
於是,我就添加diseaseTableViewController到navigationController:
diseaseTableViewController = [[navigationController viewControllers] objectAtIndex:1];
導致:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController viewControllers]: unrecognized selector sent to instance
我嘗試在該類實現中填充DiseaseTableViewController而不是AppDelegate,但在UI中再次以空白表格結束。
任何想法?
謝謝,但我想你稍稍偏出了來自我可憐的解釋的問題!只有DiseaseTableViewController(有一系列疾病)在標籤1(第二個標籤)上,其餘的是不同的視圖控制器。因此,我會有5種疾病作爲表中的條目(這是否有意義,或者我可以在DiseaseTableViewController的viewDidLoad方法或它的視圖?)。我已經有一個UiNavigationController指向DiseasTableViewController,但不斷得到該選擇錯誤 – oliveromahony 2012-02-24 19:16:31