我需要在我的网络视图(IOS)中上传一张本地图片。
显然,苹果似乎对此有一些问题。
2016-04-06 18:47:37.337 DemoWebView〔839:112324〕警告:尝试其视图不在窗口层次结构中!
(iOS 8 SDK:模式UIWebView和相机/图像选择器)
尽管我做了大量的研究,但我没有找到解决问题的办法。
如果有人能帮我的话。。我将不胜感激。
类:ViewController
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setFrame:CGRectMake(80, 150, 160, 60)];
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"Click Here !" forState:UIControlStateNormal];
[self.view addSubview:button];
}
-(void) buttonClicked:(UIButton*)sender{
ViewController2 * test = [[ViewController2 alloc]init];
[self presentViewController:test animated:true completion:NULL];
}
@end
类:ViewController2
@interface ViewController2 : UIViewController
@end
#import "ViewController2.h"
@interface ViewController2 ()
@property (strong, nonatomic) UIWebView *webView;
@end
@implementation ViewController2
- (void)viewDidLoad {
[super viewDidLoad];
_webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = _webView;
[_webView loadHTMLString:@"<br /><br /><input type="file" accept="image/*;capture=camera">" baseURL:nil];
}
@end
DemoProjet:
Thks
您正试图从第一个ViewController间接呈现UIWebview,这就是您收到警告消息的原因。试试这个:
#import "ViewController2.h"
@interface ViewController2 (){
UIWebView *webView;
}
@end
@implementation ViewController2
- (void)viewDidLoad {
[super viewDidLoad];
webView = [[UIWebView alloc] init];
[self.view addSubview:webView]
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
webView.frame = [UIScreen mainScreen].bounds;
[_webView loadHTMLString:@"Your_html_string" baseURL:nil];
}
}
@end
更新:我看到你的问题包含链接,我发现你没有覆盖这个方法
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if ( self.presentedViewController)
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
它与覆盖一起工作。非常感谢你的回答。
编辑
我明白为什么我第一次尝试就不起作用。。在我的主应用程序中,我有一个UINavigationController类,但我继续覆盖UIViewController类中的disse方法。