开发者

Why is my UIWebView not scrollable?

开发者 https://www.devze.com 2022-12-30 13:32 出处:网络
In my most frustrating roadblock to date, I\'ve come across a UIWebView that will NOT scroll! I call it via this IBAction:

In my most frustrating roadblock to date, I've come across a UIWebView that will NOT scroll! I call it via this IBAction:

-(IBAction)session2ButtonPressed:(id)sender
{   
    Session2ViewController *session2View = [[Session2ViewController alloc]initWithNibName:@"Session2ViewController" bundle:nil];
    self.addictionViewController = session2View;
    [self.view insertSubview:addictionViewController.view atIndex:[self.view.subviews count]];
    [session2View release];
}

In the viewDidLoad of Session2ViewController.m, I have

- (void)viewDidLoad 
{
    [super viewDidLoad];

    // TRP - Grab data from plist
    // TRP - Build file path to the plist
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Addiction" ofType:@"plist"];

    // TRP - Create NSDictionary with contents of the plist
    NSDictionary *addictionDict = [NSDictionary dictionaryWithContentsOfFile:filePath];

    // TRP - Create an array with contents of the dictionary
    NSArray *addictionData = [addictionDict objectForKey:@"Addiction1"];
    NSLog(@"addictionData (array): %@", addictionData);

    // TRP - Create a string with the contents of the array
    NSString *addictionText = [NSString stringWithFormat:@"<DIV style='font-family:%@;font-size:%d;'>%@</DIV>", @"Helvetica", 18, [addictionData objectAtIndex:1]];
    addictionInfo.backgroundColor = [UIColor clearColor];

 开发者_如何学Go   // TRP - Load the string created and stored into addictionText and display in the UIWebView
    [addictionInfo loadHTMLString:addictionText baseURL:nil];
    // TODO: MAKE THIS WEBVIEW SCROLL!!!!!!

}

In the nib, I connected my web view to the delegate and to the outlet. When I run my main project, the plist with my HTML code shows up, but does not scroll. I copied and pasted this code into a new project, wired the nib the exact same way, and badda-boom badda-bing. . . it works. I even tried to create a new nib from scratch in this project, and the exact same code would not work.

Whiskey

Tango

Foxtrot

Any ideas???

Thanks! Thomas


I think your problem is related to having two view controllers live at the same time. That causes problems because the view controllers are in the responder chain.

By adding the addictionViewController.view as a subview you've got two controllers active and you've loaded one nib on top of another. It's a miracle you're not seeing more problems than just the lack of scrolling in the web view.

All the views active at anyone time should be controlled by a single controller. The only exceptions to this rule are navigation controllers and tabbar controllers (which don't behave the same as other controllers.) For all other views, its one controller per screen.

You need to either merge the two controllers or create two entirely separate views that display one at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消