views:

64

answers:

3

hi i wished to randomly load a view. the views are called view1 view2 and view3 below is the code im using. can any one tell me the the code i should place in the case section to replace - (void)viewDidLoad self.view = view1; etc as this is not working thanks

- (void)viewDidLoad {
    [super viewDidLoad];

 NSString *title = nil;
 NSString *path = nil;

 int Number = arc4random() % 3;
 switch(Number) {
 case 0:
         - (void)viewDidLoad {
             self.view = view1;
         }

 break;
 case 1:
         - (void)viewDidLoad {
         self.view = view2;
         }

 break;

 case 2:
             - (void)viewDidLoad {
                self.view = view3;
             }

 break;
A: 

Your code only defines the inner function in the function, and doesn't call it.

KatokichiSoft
how should i call it
johnathan bridges
KatokichiSoft
yes it did the same for me. ill going to start the whole project from scratch and go over every thing agin with more study material. the book i had that covered it i lent out and it disappeared into that black hole
johnathan bridges
+1  A: 

You should remove the:

             - (void)viewDidLoad {

In each case statement, as well as the ending braces after it.

Andy Riordan
+1  A: 
switch(Number) {
    case 0:
         self.view = view1;
         break;
    case 1:
         self.view = view2;
         break;
    case 2:
         self.view = view3;
         break;
}
codelark
Or, more simply: `id views[] = {view1, view2, view3}; self.view = views[Number];`
Chuck
I thought I would match the solution as close to his code as possible so that he could spot why it wasn't working.
codelark