在我的应用程序中有2个视图(打开按钮按下),一个是显示Web链接,另一个是显示一些文本。在第一个视图中,我使用了一个UIWebView并在其中显示了一个Web链接。在第二个视图中,我已经在UITextView中显示了一些文本。 现在,当我按下按钮切换这些视图时,有时Web视图显示文本视图,有时textview和textview发生相同的事情,意味着随机这些视图显示任何视图Web或文本。 两种观点彼此完全不同。
以下是代码:
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;
}
}
我通过UITextView在help.xib中显示文本。
答案 0 :(得分:0)
使用以下代码作为参考
-(void) buttonPressed:(id) sender
{
if(SwitchToLinkView)
{
[myTextView removeFromSuperview];
[self.view addSubview:myWebLinkView];
}
else
{
[myWebLinkView removeFromSuperview];
[self.view addSubview:myTextView];
}
}
答案 1 :(得分:0)
答案 2 :(得分:0)
您是否随机显示视图,因为我无法理解您的ibaction中的逻辑。