IOS growth path-interface switching and Data Transmission

Source: Internet
Author: User

Logical process: ViewController. xib is the first interface, which displays the name, price, and summary attributes of Movie object storage.

-(Void) viewDidLoad: This method assigns values to the three attributes and displays them on the page. When you click the Edit button on the page, it calls

-(IBAction) Edit :( id) sender; the method is switched to the EditViewController. xib interface, and the value of name, price, and summary in the first interface is also passed to this interface,

Call the-(void) viewDidLoad method in the EditViewController class to assign values to the Movie object in this class and display it in the TextField control.

-(BOOL) textFieldShouldReturn :( UITextField *) textField;

-(Void) textFieldDidEndEditing :( UITextField *) textField;

These two methods modify the three property values and re-pay the modified value to the Movie object. Then, click the Back button to call

-(IBAction) Back :( id) The sender method returns the previous interface, and

-(Void) viewWillAppear :( BOOL) animated
Method to display the modified value in the second interface in the first interface.

 

First interface:
/* ViewController. h */# import <UIKit/UIKit. h> @ class Movie; @ interface ViewController: UIViewController {// create the Movie object Movie * movie; // define three labels UILabel * titleLabel; UILabel * priceLabel; UILabel * summaryLabel ;} @ property (nonatomic, retain) Movie * movie; @ property (nonatomic, retain) IBOutlet UILabel * titleLabel; @ property (nonatomic, retain) IBOutlet UILabel * priceLabel; @ property (nonatomic, retain) IBOutlet UILabel * summaryLabel; // defines the method for switching the interface-(IBAction) Edit :( id) sender; @ end

 

/* Viewcontroller. M */# import "viewcontroller. H "# import" movie. H "# import" editviewcontroller. H "@ implementation viewcontroller @ synthesize movie; @ synthesize titlelabel; @ synthesize pricelabel; @ synthesize summarylabel;-(void) handle {[Super variable]; // release any cached data, images, etc that aren't in use .} # pragma mark-view lifecycle // initialization when the view is created, only one-(void) vie is called Wdidload {[Super viewdidload]; // initialize the created movie object to name Price summary movie = [[Movie alloc] initwithname: @ "Iron Man" andprice: [nsnumber numberwithint: 122] andsummary: @ "the movie is good"]; // Add the name to the label titlelabel. TEXT = movie. name; // price is of the nsnumber type. It is converted to the int type and added to the pricelabel in the form of a string. Int TMP = [movie. price intvalue]; pricelabel. TEXT = [nsstring stringwithformat: @ "% d", TMP]; // Add the summary to the summarylabel Su Mmarylabel. TEXT = movie. summary; // The above assignment process can be written as // self. movie = movie;} // this method is called every time you enter the view to grant the modified value to label-(void) viewwillappear :( bool) animated {nslog (@ "% @", movie); titlelabel. TEXT = movie. name; int TMP = [movie. price intvalue]; pricelabel. TEXT = [nsstring stringwithformat: @ "% d", TMP]; summarylabel. TEXT = movie. summary; [Super viewwillappear: animated];}-(void) viewdidunload {[Super viewdidunload]; self. Titlelabel = nil; self. pricelabel = nil; self. summarylabel = nil; // release any retained subviews of the main view. // e.g. self. myoutlet = nil;}-(void) viewdidappear :( bool) animated {[Super viewdidappear: animated];} (void) viewwilldisappear :( bool) animated {[Super viewwilldisappear: animated];}-(void) viewdiddisappear :( bool) animated {[Super viewdiddisappear: animated];}-(bool) shouldautorotatetointer Faceorientation :( uiinterfaceorientation) interfaceorientation {// return YES For supported orientations return (interfaceorientation! = Uiinterfaceorientationportraitupsidedown);} // implement the interface switch and pass the value to the past-(ibaction) EDIT :( ID) sender {// The editviewcontroller * tmpedit = [[editviewcontroller alloc] initwithnibname: @ "editviewcontroller" Bundle: Nil] interface for converting from this class interface to the editviewcontroller class; //-(void) presentmodalviewcontroller :( uiviewcontroller *) modalviewcontroller animated :( bool) animated; // print the nslog (@ "% @", movie) in the movie object ); // assign the value (name Price summary) in movie to editmovie tmpedit in the editviewcontroller class. editmovie = movie; // sets the page flip result tmpedit. modaltransitionstyle = custom;/* Other page turning effects: uimodaltransitionstylecoververtical neural coloring algorithm */[self presentmodalviewcontroller: tmpedit animated: Yes]; // implement page switching [tmpedit autorelease]; nslog (@ "Edit function called");} @ end
Interface display:

 

 

Second Interface:
/* Editviewcontroller. H */# import <uikit/uikit. h> @ Class movie; @ interface editviewcontroller: uiviewcontroller {Movie * editmovie; // movie object // three textfield objects uitextfield * textname; uitextfield * textprice; uitextfield * textsummary ;} @ property (nonatomic, retain) iboutlet uitextfield * textname; @ property (nonatomic, retain) iboutlet uitextfield * textprice; @ property (nonatomic, retain) iboutlet uitextfield * textsummary; @ property (nonatomic, retain) Movie * editmovie;-(ibaction) Back :( ID) sender; // defines the method returned to the previous interface @ end

 

/* EditViewController. m */# import "EditViewController. h "# import" Movie. h "@ implementation EditViewController @ synthesize editMovie; @ synthesize textName; @ synthesize textPrice; @ synthesize textSummary;-(id) initWithNibName :( NSString *) bundle :( NSBundle *) nibBundleOrNil {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(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/* // Implement loadView to create a view hierarchy programmatically, without using a nib. -(void) loadView {} * // Add the value obtained from the ViewController class to three texts on the Interface-(void) viewDidLoad {NSLog (@ "editMovie = % @", editMovie); textName. text = editMovie. name; // convert the NSNumber type value to the int type value int tmp = [editMovie. price intValue]; textPrice. text = [NSString stringWithFormat: @ "% d", tmp]; textSummary. text = editMovie. summary; [super viewDidLoad];}-(void) viewDidUnload {self. textName = nil; self. textPrice = nil; self. textSummary = nil; [super viewDidUnload];}-(BOOL) returns :( UIInterfaceOrientation) interfaceOrientation {return (interfaceOrientation = UIInterfaceOrientationPortrait);} // returns the previous interface (IBAction) back :( id) sender {//-(void) dismissModalViewControllerAnimated :( BOOL) animated; method [self dismissModalViewControllerAnimated: YES]; NSLog (@ "Back function called ");} -(void) dealloc {[textName release]; [textPrice release]; [textSummary release]; [editMovie release]; [super dealloc];} // Add a label to return the value every time it is modified # pragma mark UITextFiledDelegate methods-(BOOL) textFieldShouldReturn :( UITextField *) textField {[textField resignFirstResponder]; return YES;} // modify the value in the second interface, and then assign the modified value to the Movie object for storage. When switching to the previous interface, use the object output-(void) textFieldDidEndEditing :( UITextField *) textField {// judgment statement to distinguish name price summary if (textName = textField) {editMovie. name = textField. text;} else if (textPrice = textField) {// The Conversion Type value is int tmp = [textField. text intValue]; // NSString-(int) intValue editMovie. price = [NSNumber numberWithInt: tmp];} else if (textSummary = textField) {editMovie. summary = textField. text;} // print NSLog (@ "% @", editMovie);} @ end
Interface display:

:

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.