2010-08-18 7 views
0

Je suis en train de mettre en œuvre le scénario suivant: Il y a un écran appelé: étude (cet écran est le RootViewController de mon onglet contrôleur de bar)plusieurs tables sur écran unique programme (sans fichier xib) iphone

Dans cet écran, je dois afficher deux tables différentes: mots et phrases

je dois faire programatically (sans un fichier nIB). Donc, je suis en train d'écrire le loadview pour la vue comme contrôleur d'étude:

// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
    //creating the view for the screen "Study" 
    CGRect cgRct = CGRectMake(0, 0, 320, 367); //define size and position of view 
    UIView *myStudyView = [[UIView alloc] initWithFrame:cgRct]; //initilize the view 
    myStudyView.autoresizesSubviews = YES; //allow it to tweak size of elements in view 
    myStudyView.backgroundColor = [UIColor brownColor]; 
    self.view = myStudyView; //set view property of controller to the newly created view 
    [myStudyView release]; 

    //creating the view for the "words" and instantiating the view controller 
    WordsTableViewController *wordsTVC = [[[WordsTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; 
    cgRct = CGRectMake(0, 10, 320, 100);//define size and position of view 
    UIView *myWordsView = [[UIView alloc] initWithFrame:cgRct];//initilize the view 
    myWordsView.autoresizesSubviews = YES;//allow it to tweak size of elements in view 
    wordsTVC.view = myWordsView;//set view property of controller to the newly created view 
    [myWordsView release]; 
    [self.view addSubview:wordsTVC.view]; 

    //creating the view for the "phrases" and instantiating the view controller 
    PhrasesTableViewController *phrasesTVC = [[[PhrasesTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; 
    cgRct = CGRectMake(0, 120, 320, 100); //define size and position of view 
    UIView *myPhrasesView = [[UIView alloc] initWithFrame:cgRct]; //initilize the view 
    myPhrasesView.autoresizesSubviews = YES; //allow it to tweak size of elements in view 
    phrasesTVC.view = myPhrasesView; //set view property of controller to the newly created view 
    [myPhrasesView release]; 
    [self.view addSubview:phrasesTVC.view]; 
} 

Je vois juste la couleur de fond brun de l'écran d'étude. Les deux tables n'apparaissent pas. Je suis sûr de faire une erreur fondamentale comme je suis un débutant total pour le développement de l'iPhone. BTW, WordsTableViewController et PhrasesTableViewController sont des sous-classes TableViewController définies séparément.

Appréciez votre aide. -Achilles

+0

Utilisez la fonction d'indentation Markdown pour clarifier votre code. – jbm

Répondre

2

Pourquoi faites-vous cela?

UIView *myWordsView = [[UIView alloc] initWithFrame:cgRct]; 
myWordsView.autoresizesSubviews = YES; 
wordsTVC.view = myWordsView; 

Vous avez effectivement dit au contrôleur de vue de ne pas l'utiliser est la référence interne à son UITableView mais d'utiliser à la place une UIView vide comme son point de vue.

Supprimez ces lignes et appelez setFrame avec les CGRects que vous avez spécifiés dans la vue du contrôleur de vue. Vous devriez voir vos vues de table alors. Comme ceci:

- (void)loadView { 
    //creating the view for the screen "Study" 
    CGRect cgRct = CGRectMake(0, 0, 320, 367); //define size and position of view 
    UIView *myStudyView = [[UIView alloc] initWithFrame:cgRct]; //initilize the view 
    myStudyView.autoresizesSubviews = YES; //allow it to tweak size of elements in view 
    myStudyView.backgroundColor = [UIColor brownColor]; 
    self.view = myStudyView; //set view property of controller to the newly created view 
    [myStudyView release]; 

    //creating the view for the "words" and instantiating the view controller 
    WordsTableViewController *wordsTVC = [[[WordsTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; 
    cgRct = CGRectMake(0, 10, 320, 100);//define size and position of view 
    [[wordsTVC view] setFrame:cgRct]; 
    [self.view addSubview:wordsTVC.view]; 

    //creating the view for the "phrases" and instantiating the view controller 
    PhrasesTableViewController *phrasesTVC = [[[PhrasesTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease]; 
    cgRct = CGRectMake(0, 120, 320, 100); //define size and position of view 
    [[phrasesTVC view] setFrame:cgRct]; 
    [self.view addSubview:phrasesTVC.view]; 
} 
+0

Notez également que l'ajout manuel de l'affichage de UIViewController à une autre vue de UIViewController entraîne un comportement géré par un cadre (viewWillAppear, autorotations, etc.). –

+0

Salut Matt, Vous êtes absolument fantastique. C'était exactement le problème et votre recommandation l'a magnifiquement réparé. Dieu vous bénisse :) - Achilles – Achilles

+0

thanxx tc, pour le signaler. Prendra soin de le gérer. – Achilles

Questions connexes