Domanda

I am trying to call a javascript function from a popover with a UITableView containing an NSArray of fonts in the iPad. The problem I am having is whenever I call the function from didselectrowatindexpath it fails to acommplish anything in the UIWebView. I am able to get the appropriate information in NSLog, but somehow the link between the two views is failing. If I assign the function to a button in the view containing the UIWebView everything works great. I am using a storyboard and the popovervew and the UIWebView share the same viewController class. This may be something very simple that I have overlooked, but I am really stuck for whatever reason. Also, If I call some other function like an alert view everything works as expected. I am sincerely grateful for any help with this issue. Thanks

Here is how I am calling the javascript function in didselectrowatindexpath:

- (void) tableView: (UITableView *) theTableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {

UITableViewCell *selectedCell = [self.myTableView cellForRowAtIndexPath:indexPath];
NSString *cellText1 = selectedCell.textLabel.text;

[myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"tinymce.activeEditor.execCommand('fontName', false, '%@');", cellText1]];

    NSLog (@"%@", cellText1);


[self.myTableView deselectRowAtIndexPath: indexPath animated: YES];
}

Here is the code for a button in the view containing the UIWebView that sets font to "Arial":

-(IBAction)changeFont:(id)sender{
[myWebView stringByEvaluatingJavaScriptFromString:@"tinymce.activeEditor.execCommand('fontName', false, 'Arial');"];
}
È stato utile?

Soluzione

I ended up using NSNotification center. I know it is not the lightest way, but it seemed to be the best (maybe only) solution for my particular need. I just post a notification from the popoverviewcontroller and set up a listener in the viewcontroller that controls the UIWebview. I then trigger an action on the notification event that calls the javascript function. It all worked well for me. I hope that this can help someone else as well.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top