Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ViviUO

macrumors 6502
Original poster
Jul 4, 2009
307
22
So I have 2 views. Let's call them View 1 and View 2.

View 1 has a UITextField named inputField and a button that opens a modal view, View 2. I also call [View 2 fillLabel], with fillLabel being a method declared in View 2.

View 2 has a label on it, named outputLabel, and a method to set it's label as mentioned above.

My View 1.m has an action assigned to it's button to display View 2 while at the same time calling [View 2 fillLabel].

However, it is not working. I have tried several different ways:

Code:
======
View 1.h
======

#import <UIKit/UIKit.h>
#import "View2ViewController.h"

@class View2ViewController;

@interface View1ViewController : UIViewController {
	IBOutlet View2ViewController *view2view;
	IBOutlet UITextField *inputTextField;


}

@property(nonatomic, retain) IBOutlet View2ViewController *view2view;
@property(nonatomic, retain) IBOutlet UITextField *inputTextField;

-(IBAction)showModal:(id)sender;
-(IBAction)hideKeyboard:(id)sender;

@end

======
View 1.m
======

#import "View1ViewController.h"

@implementation View1ViewController

@synthesize inputTextField, view2view;

-(IBAction)showModal:(id)sender {
	view2view.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
	[self presentModalViewController:view2view animated:YES];
	
	[view2view fillLabel]; 
	
}

Code:
======
View 2.h
======

#import <UIKit/UIKit.h>
#import "View1ViewController"

@class View1ViewController;


@interface View2ViewController : UIViewController {
	IBOutlet UILabel *outputLabel;
	
	View1ViewController *view1;

}

@property (nonatomic, retain) UILabel *outputLabel;
@property (nonatomic, retain) View1ViewController *view1;

-(IBAction)resignModal:(id)sender;
-(void)fillLabel;

@end

======
View 2.m
======

#import "View2ViewController.h"
#import "View1ViewController.h"

@implementation View2ViewController

@synthesize outputLabel, view1;

-(IBAction)resignModal:(id)sender {
	[self dismissModalViewControllerAnimated:YES];
	
}

-(void)fillLabel {
	
	label.text=view1.inputTextField.text;
	
}

Basically, I am having trouble in -(void)fillLabel.

.... i even tried converting the text from the TextField into a string ... no luck.

Am I missing something? Do I have to make a whole class just to share a single line of text?
 
Class View2ViewController has a member variable named "view1", but where do you initialize it? Same question about class View1ViewController and member variable "view2view".
 
Try:

Code:
======
View 1.h
======
 
-(IBAction)showModal:(id)sender {
	view2view.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
	[view2view [fillLabel:inputTextField.text]]; 
	[self presentModalViewController:view2view animated:YES];
	
	
}

Code:
======
View 2.h
======
 

-(void)fillLabel:(NSString *) suppliedString {
	
	[label setText:suppliedString ]; 

}
 
Class View2ViewController has a member variable named "view1", but where do you initialize it? Same question about class View1ViewController and member variable "view2view".

I use that later on and left it out for this question. :D

forum user said:
Try:

Code:
======
View 1.h
======
 
-(IBAction)showModal:(id)sender {
	view2view.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
	[view2view [fillLabel:inputTextField.text]]; 
	[self presentModalViewController:view2view animated:YES];
	
	
}


Code:
======
View 2.h
======
 

-(void)fillLabel:(NSString *) suppliedString {
	
	[label setText:suppliedString ]; 

}

This didn't seem to work either, I will have to keep playing with it I guess. :confused:

This seems really easy to do. I guess I am just a special case.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.