我需要在我的网页浏览(IOS)中上传本地图片。
显然,Apple似乎有一些问题。
2016-04-06 18:47:37.337 DemoWebView [839:112324]警告:尝试 目前的视图不在窗口层次结构中!
(iOS 8 SDK: modal UIWebView and camera/image picker)
尽管我进行了广泛的研究,但我找不到解决问题的方法。
如果有人能帮助我......我会非常感激。
class: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
class: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
答案 0 :(得分:0)
您正尝试从第一个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];
}
}
答案 1 :(得分:0)
它适用于覆盖。非常感谢您的回答。
修改
我理解为什么它在第一次尝试时没有工作..在我的主应用程序中,我有一个UINavigationController类,但我继续覆盖我的UIViewController类中的dismiss方法。