English 中文(简体)
iPhone: How I can Access Data in a View Controller Class from Another Controller Class?
原标题:

In my application I have one Entry form in which there are six Text fields

  1. Name :UITextField
  2. Date of Birth :UITExtField
  3. Age:UITextField
  4. Address :UITextField
  5. Phone No :UITextField
  6. Image : UIIMageView

Now What I want is that I want all these fields value in the same fields of other ViewController class. How it could be possible .

Please help me I really need help for this..

Special Thanks in Advance

问题回答

You can achieve that by implementing getter and setters in the delegate class.

In delegate .h file

Include UIApplication delegate

 @interface DevAppDelegate : NSObject <UIApplicationDelegate>

 NSString * currentTitle;

- (void) setCurrentTitle:(NSString *) currentTitle;
- (NSString *) getCurrentTitle; 

In Delegate implementation class .m

-(void) setCurrentLink:(NSString *) storydata{
currentLink = storydata;

}

-(NSString *) getCurrentLink{
if ( currentLink == nil ) {
currentLink = @"Display StoryLink";
}
return currentLink;
}

So the variable you to assess is set in the currentlink string by setters method and class where you want the string ,just use the getter method.

What you really need is a data model object.

A data model is an object of dedicated class that stores and logically manipulates the applications data. It should be an entirely separate class from either the views or the view controllers. It should universally accessible within the app preferably as a singleton.

(Warrior s solution is a lightweight solution that turns the app delegate into the data model object. It will work for small, quick and dirty apps. It will breakdown as the data grows more complex.)

In your case, controller A would write the collected data to the data model and then it would close its view. Controller B would upon activating, check the data model and read out the information it needed.

The beauty of using the data model is that it has the flexibility of an old style global variable combined with the safety of using a class dedicated to to maintaining the data s integrity.

For more details see: Pattern for Ownership and References Between Multiple Controllers and Semi-Shared Objects?

and

Simple MVC setup / design?





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签