2011-04-28 5 views
0

Dans mon application, il y a 2 vues (bouton d'activation enfoncé), une pour afficher un lien Web et une autre pour afficher du texte. En première vue, j'ai pris un UIWebView et montré un lien web dedans. En 2ème vue j'ai pris UITextView n affichant du texte. Maintenant, comme je change de vue par bouton pressé parfois la vue web montre la vue de texte et parfois textview et la même chose se produit avec textview, signifient aléatoirement ces vues montrent n'importe quelle vue soit web ou texte. Les deux vues sont totalement différentes les unes des autres.Problème lors de la commutation des vues

Voici le code:

web.h

@interface web : UIViewController { 
    NSInteger bTag; 
    IBOutlet UIWebView *webShow; 
} 
@property(nonatomic,readwrite) NSInteger bTag; 
@property (nonatomic, retain) IBOutlet UIWebView *webShow; 
-(IBAction)menuButtonPressed:(id) sender; 
@end 

web.m

#import "help.h" 
#import "web.h" 


@implementation web 

@synthesize bTag; 
@synthesize webShow; 

-(IBAction)menuButtonPressed:(id) sender 
{ 
    self.bTag=[sender tag]; 

    switch (self.bTag) 
    { 

     case 1: 
     { 
      help *hv=[[help alloc] initWithNibName:nil bundle:nil]; 
      hv.modalTransitionStyle=UIModalTransitionStyleCoverVertical; 
      [self presentModalViewController:hv animated:YES]; 
      [hv release]; 
      break; 
     } 
     case 2: 
     { 
      web *wv=[[web alloc] initWithNibName:nil bundle:nil]; 
      wv.modalTransitionStyle=UIModalTransitionStyleCoverVertical; 
      [self presentModalViewController:wv animated:YES]; 
      [wv release]; 
      break; 
     } 
     default: 
      break; 
    } 

} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    NSURL *url = [NSURL URLWithString:@"http://www.unicurd.com.sg/"]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    [webShow loadRequest:request]; 
} 

- (void)dealloc { 
    [super dealloc]; 
    [webShow release]; 
} 
@end 

help.h

@interface help : UIViewController { 


    NSInteger bTag; 
    } 

@property(nonatomic,readwrite) NSInteger bTag; 


-(IBAction)menuButtonPressed:(id) sender; 

@end 

help.m

#import "help.h" 
#import "web.h" 


@implementation help 

@synthesize bTag; 

-(IBAction)menuButtonPressed:(id) sender 
{ 
    self.bTag=[sender tag]; 

    switch (self.bTag) 
    { 

     case 1: 
     { 
      help *hv=[[help alloc] initWithNibName:nil bundle:nil]; 
      hv.modalTransitionStyle=UIModalTransitionStyleCoverVertical; 
      [self presentModalViewController:hv animated:YES]; 
      [hv release]; 
      break; 
     } 
     case 2: 
     { 
      web *wv=[[web alloc] initWithNibName:nil bundle:nil]; 
      wv.modalTransitionStyle=UIModalTransitionStyleCoverVertical; 
      [self presentModalViewController:wv animated:YES]; 
      [wv release]; 
      break; 
     } 
     default: 
      break; 
    } 

} 

Je l'affichage du texte dans help.xib en prenant UITextView.

+2

Pouvez-vous montrer votre code? –

+0

Je pense que ce que vous voulez est un UITabBarController – lukya

Répondre

0

Utilisez le code ci-dessous comme référence

-(void) buttonPressed:(id) sender 
{ 
    if(SwitchToLinkView) 
    { 
     [myTextView removeFromSuperview]; 
     [self.view addSubview:myWebLinkView]; 
    } 
    else 
    { 
     [myWebLinkView removeFromSuperview]; 
     [self.view addSubview:myTextView]; 
    } 
} 
0

Vous pouvez utiliser dismissModalViewControllerAnimated

+0

Je ne peux pas l'utiliser parce que j'ai beaucoup (5) vues donc dans le cas de commutateur il y a 5 cas de sorte que je peux passer de n'importe quelle vue à n'importe quelle vue. Et à travers rejectModalViewControllerAnimated nous pouvons passer à la vue précédente. –

0

Êtes-vous montrant la vue au hasard, comme je ne pouvais pas comprendre la logique à l'intérieur du votre IBAction.

Questions connexes