vendredi 8 mai 2015

View factory for iOS

I am trying to create a View factory for iOS and I am getting into some trouble. The view factory should be a able to create multiple UIImageViews, MKMapViews or UIWebViews and add them to a view vertically. I have a problem with the web view cause I have to wait for webViewDidFinishLoad. If the methods are implemented in the ViewController which implements the UIWebViewDelegate and the delegate of the webviews is set to the controller everything works fine. The thing is that I want to put all of this in a separate class but the webViewDidFinishLoad is never been called. Is there a way to achieve that? Tell me if you need any code

Code: Part is added

- (void)addPart
{
  if (self.viewPartStrings.count != 0) {
    NSString *viewPartString = [self.viewPartStrings objectAtIndex:0];
    NSString *viewPartIdentifier = [self getViewPartIdentifier:viewPartString];
    NSString *viewPartDefinition = [self getViewPartDefinition:viewPartString];
    if ([viewPartIdentifier isEqualToString:kWeb]) {
        [self createTextWebViewPart:viewPartIdentifier];
    } else if ([viewPartIdentifier isEqualToString:kMap]) {
        [self createMapViewPart:viewPartDefinition];
    } else if ([viewPartIdentifier isEqualToString:kImage]) {
        [self createImageViewPart:viewPartDefinition];
    }
  }
}

Views are created:

- (void)createTextWebViewPart:(NSString *)viewPartText
{
    WebViewPart *webViewPart = [[WebViewPart alloc]initWithFrame:[self getViewPartFrameForHeight:0]];
    [webViewPart createViewForText:viewPartText];
    [webViewPart setDelegate:self];
}

- (void)createImageViewPart:(NSString *)viewPartDefinition
{
    //create image
}

- (void)createMapViewPart:(NSString *)viewPartDefinition
{
    //create map
}

But here is the point. This method is never called. Not if the class extends NSObject and not if the class extends UIView:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];
    int height = frame.size.height + 70;
    [self addToView:webView forHeight:height];

}

Aucun commentaire:

Enregistrer un commentaire