开发者

transfer information between navigation based application

I have application

I want a button to o开发者_Go百科pen another screen with done button

after click this button a data be transfered from the current screen to the previous one

like opening options screen , how to let the main view know the changes be done on this subview

Best regards


You can use properties for this.

Create a property in the second class: .h file

@interface DetailViewController : UIViewController {

NSString *head;
}
@property(nonatomic,retain)NSString *head;

@end  

in .m file

@synthesize head;

Now in your firstviewcontroller or first class

if (dt==nil) {
    DetailViewController *d = [[DetailViewController alloc]initWithNibName:@"Detailview" bundle:nil];
    self.dt = d;
    [d release];
}

dt.head=itemsum;

[self.navigationController pushViewController:self.dt animated:YES];


Suppose you have to pass NSString to other class then declare one Nsstring in second class and make accessor method for nsstring and then call this code from first view controller

yournextviewcontroller *viewcontroller = [[yournextviewcontroller alloc] initWithNibName:@"yournextviewcontroller" bundle:nil];
            viewcontroller.Stringname = name;

[self.navigationController viewcontroller:evernotebook animated:YES];


You can take UIView as IBOutlet in the same ViewController. Show that view with click on Button like

 IBOutlet UIView *yourAnotherScreenView; //Bind this to your view in XIB file.

 [self.view addSubView:yourAnotherScreenView];
 [self.view bringSubViewtoFront:yourAnotherScreenView];

Take Done button on the view and wireup the action event in the same controller and do the necessary stuff as required.


Use the simple delegate concept of Objective-C .

Check very simple answers in the below post for using delegate in Objective-C .

How do I set up a simple delegate to communicate between two view controllers?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜