I have two views that are working under a UINavigationController.
Basically, what I want to happen is this: after the user types in some HTML Code in the UITextView (txtCode), I want them to be able to click the UIButton and basically push the UINavigationController to the PreviewController view and in the WebView, I want their HTML Code to be previewed there.
Here is my UIButton code:
- (IBAction) switchPage:(id)sender {
if(self.previewController == nil)
{
PreviewController *viewTwo = [[PreviewController alloc]
initWithNibName:@"PreviewController" bundle:[NSBundle mainBundle]];
self.previewController = viewTwo;
[viewTwo release];
}
[self.navigationController pushViewController:self.previewController animated:YES];
}
Now someone told me that this line of code below makes it work but I have no idea how to implement it so that it pushes the value of the UITextView and preview it in a new view:
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
I placed this where you told me in the AddViewController:
self.previewController.webViewCode = [[NSString alloc] initWithString:txtCode.text];
Now I created an NSString called webViewCode, implemented and referred to it in both my AddViewController and my PreviewController. I also have this code in the PreviewController's viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadHTMLString:(NSString *)webViewCode baseURL:(NSURL *)index];
webView.scalesPageToFit = true;
}
But it still returns errors. It doesn't show the error when building the app, but when I click the UIButton in the app.
so you are pushing to previewController on each and every button click. first you need to pass the text field text to previewController to load in in aweb view. for that take an nsstring variable in previewController and synthesize it. and then pass your text field text to previewController using
self.previewController.yourNsstringobject = [[NSString alloc] initWithString:textfield.text];
before the line
[self.navigationController pushViewController:self.previewController animated:YES];
make sure that,release the nsstring object in dealloc methode in previewController