Passing UITextView values to ModalViewController from parent View Controller?

Here is what I would do (taken from my current project).

Here is what I would do (taken from my current project): #import @interface DictionaryViewController : UIViewController { NSString *word; NSString *definition; IBOutlet UIWebView *webView; IBOutlet UINavigationItem *navItem; } @property(nonatomic, copy) NSString *word; @property(nonatomic, copy) NSString *definition; @property(nonatomic, retain) IBOutlet UIWebView *webView; @property(nonatomic, retain) IBOutlet UINavigationItem *navItem; -(IBAction) done; -(IBAction) pronounce; @end Here is the implementation: #import "DictionaryViewController. H" #import "TBXML. H" #import "Lexicontext.

H" #import "Lexicontext+Pronounce. H" @implementation DictionaryViewController @synthesize word, definition, webView, navItem; -(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (keyPath isEqualToString:@"word") { definition = Lexicontext sharedDictionary definitionAsHTMLFor:word; self webView loadHTMLString:definition baseURL:nil; navItem. Title = word; } } -(void) done { self dismissModalViewControllerAnimated:YES; } -(void) pronounce { Lexicontext sharedDictionary pronounce:word; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = super initWithNibName:nibNameOrNil bundle:nibBundleOrNil; if (self) { // Custom initialization self addObserver:self forKeyPath:@"word" options:0 context:nil; } return self; } - (void)dealloc { super dealloc; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview.

Super didReceiveMemoryWarning; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { super viewDidLoad; // Do any additional setup after loading the view from its nib. Self webView loadHTMLString:definition baseURL:nil; navItem.

Title = word; UIScrollView *scrollview = webView subviews objectAtIndex:0; scrollview. Bounces = NO; } - (void)viewDidUnload { super viewDidUnload; // Release any retained subviews of the main view. // e.g.Self.

MyOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end How you would use this: -(void) somethingHappened:(id) sender { DictionaryViewController *dvc = DictionaryViewController alloc initWithNibName:@"DictionaryViewController" bundle:NSBundle mainBundle; dvc. Word = @"Some word to look up"; self presentModalViewController:dvc; dvc release; }.

Thanks for providing your code. It is very generous of you. I will go with your way if I can't fix my code.

– SerPiero May 28 at 5:37.

I am guessing you've used IB to create the views. In which case ArticleViewController alloc init autorelease; won't load that interface for you. You will have to use ArticleViewController alloc initWithNibName:@"ArticleViewController" bundle:nil withText:@"Test!"; to get the desired result.

But then there is something that isn't right about the way you've implemented your initializer. Self. ArticleTextView = UITextView alloc init; self.articleTextView.

Text = text retain; Firstly XIB will have create the text view and linked to the articleTextView property. So no need to create it again. Moreover, this view hasn't been added as a subview to your controller's view property so it won't appear on screen.

The IB created text view will remain on screen but without a reference. You should remove the first line. Secondly, the text property in the text view is a copied property.

So your retain can be considered a leak. Self.articleTextView. Text = text; Everything else seems to be ok.

EDIT -(IBAction)showArticleView:(UIButton *)sender{ storyView = ArticleViewController alloc initWithNibName:@"ArticleViewController" bundle:NSBundle mainBundle; storyView.articleTextView. Text = articles objectAtIndex:sender tag; storyView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve; storyView. ModalPresentationStyle = UIModalPresentationPageSheet; self presentModalViewController:storyView animated:YES; storyView release; }.

Thanks soooo much for quick response to my question. I edited my code according to your answer. It seems to work, but not exactly.

I tried add subview to my controller's view, but I was not sure where to add it. So, I just added it to my parent view controller. Can you please look at my code in parent view controller and tell me where I am doing wrong?

Thanks in advance. – SerPiero May 28 at 5:35 You don't need to do self. View addSubview:storyView04 view; when you're presenting it modally.

– Deepak May 28 at 6:28 So, I removed self. View addSubview:storyView04 view; and edited viewDidLoad part of ArticleViewController. M class.

Now, on the console, I am getting the string "This is a test! " which is what I wanted :) ModalView is also acting properly. Now, instead of the fixed string, I need to pass the text values from my parsed articles.Is there any easy way to do that?

Thanks. PS: I also have another question regarding my project, which I posted here: stackoverflow.Com/questions/6164777/… – SerPiero May 28 at 22:52 Easy way to what? I am assuming the parent view controller will have access to the array of articles as it displays some sort of article identification.

If you've used buttons, you will have to tag them with a matching id. – Deepak May 28 at 23:00 That said, you don't need a different method for every button. Map them to a single method like I have shown in the edit.

– Deepak May 28 at 23:03.

Your property articleTextView is getting the string "TESTING! TESTING! ".

If you can't see it on the UITextview you have on screen, it is because you hooked it up to an instance variable with the same name (articleTextView). You might want to remove the IBOutlet from the instance variable and put it on the property. @property (nonatomic, retain) IBOutlet UITextView *articleTextView; you might not need to hook it up again.

Hope this clears up a misunderstanding you probably have between ivars and properties.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions