【发布时间】:2015-06-23 10:37:19
【问题描述】:
我有一个ViewController (A),包含 n 个按钮。所有按钮都映射到包含WebView 的其他ViewController(B) 以显示不同的PDF。
我会知道如何根据按下的按钮更改路径,而不是创建 n ViewController。
我的错误尝试:
1-使用ClassB中的按钮标签viewDidLoad:(id)sender(我加了sender)
([sender tag] == 1)
//Action
2- 从其他类访问公共变量
在 A.h 类中
@interface ClassA : UIViewController
{
@public
NSString *path;//was var
}
@property (readwrite, nonatomic) NSString* path;
ClassA.m
- (IBAction)button1:(UIButton *)sender{
path=[[NSBundle mainBundle]
pathForResource:@"filename" ofType:@"pdf"];
}
B 类:
ClassB *obj ;
NSURL *url= [NSURL fileURLWithPath:obj->path];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[_webview loadRequest:request];
[_webview setScalesPageToFit:YES];
【问题讨论】:
-
你使用故事板或 xib]
-
@Anbu.Karthik 我正在使用故事板
标签: ios objective-c iphone xcode uiviewcontroller