Objective c 在视图控制器之间传输UILabel数据

Objective c 在视图控制器之间传输UILabel数据,objective-c,xcode,label,uidatepicker,transfer,Objective C,Xcode,Label,Uidatepicker,Transfer,在我的应用程序中,我有一个视图控制器,它包含两个标签和一个UIDatePicker。当我更改该日期选择器的值时,标签将匹配相同的数据 在第二个标签旁边,我有一个按钮,使用垂直过渡转到另一个视图控制器。在第二个视图中,我有另一个标签和一个UIDatePicker。当我更改UIDatePicker的值时,它会将同一视图控制器中的标签值更改为示例2011年11月6日。有一个“完成”按钮,用于使用Disclease modalViewController解除视图控制器。我想知道的是,如何将标签数据从第二

在我的应用程序中,我有一个视图控制器,它包含两个标签和一个UIDatePicker。当我更改该日期选择器的值时,标签将匹配相同的数据

在第二个标签旁边,我有一个按钮,使用垂直过渡转到另一个视图控制器。在第二个视图中,我有另一个标签和一个UIDatePicker。当我更改UIDatePicker的值时,它会将同一视图控制器中的标签值更改为示例2011年11月6日。有一个“完成”按钮,用于使用Disclease modalViewController解除视图控制器。我想知道的是,如何将标签数据从第二个视图控制器传输到第一个视图控制器中的标签

我是一个相当新的程序员,所以我感谢所有的帮助

这是我的密码:

ViewController 1.h:

ViewController 2.h:


请仅包括相关代码-默认情况下添加的样板方法不值得添加到您的问题中。可能重复
  #import <UIKit/UIKit.h>

@interface PushedViewController : UIViewController {

    IBOutlet UIDatePicker *datePicker;
    IBOutlet UILabel *product; 
    IBOutlet UILabel *howLong1;
}

@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) IBOutlet UILabel *product;
@property (nonatomic, retain) IBOutlet UILabel *howLong1;

-(IBAction)choose:(id)sender;
-(IBAction)gotoWarranty:(id)sender;


@end
#import "PushedViewController.h"
#import "WarrantyNextViewController.h"


@implementation PushedViewController

@synthesize datePicker;
@synthesize product, howLong1;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(IBAction)choose:(id)sender{    
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    NSString *myDate;
    myDate =  [dateFormatter stringFromDate:[datePicker date]];

    product.text = myDate;

    //UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Purchased on" message:myDate delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
    //[alert show];
    //[alert release];
    //[myDate release];        
}

-(IBAction)gotoWarranty:(id)sender{
    WarrantyNextViewController *any = [[WarrantyNextViewController alloc] initWithNibName:@"WarrantyNextViewController" bundle:nil];
    any.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:any animated:YES];
    [any release];
}

- (void)dealloc
{
    [datePicker release];
    [product release];
    [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
{
    product.text = @"Use Date Picker";
    self.title = @"Product";

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    self.datePicker= nil;

    [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
#import <UIKit/UIKit.h>
@class PushedViewController;

@interface WarrantyNextViewController : UIViewController{
    IBOutlet UIDatePicker *datePicker2;
    IBOutlet UILabel *product2; 

}

@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker2;
@property (nonatomic, retain) IBOutlet UILabel *product2;

-(IBAction)Done:(id)sender;
-(IBAction)Choose2:(id)sender;

@end
#import "WarrantyNextViewController.h"
#import "PushedViewController.h"

@implementation WarrantyNextViewController
@synthesize datePicker2, product2;                          

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

    //NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    //[prefs setObject:label2.text forKey:@"label"];
}

-(IBAction)Choose2:(id)sender{    
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    NSString *myDate;
    myDate =  [dateFormatter stringFromDate:[datePicker2 date]];
    product2.text = myDate;

    //UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Purchased on" message:myDate delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
    //[alert show];
    //[alert release];
    //[myDate release];

}



- (id)initWithNibName:(NSString *)nibNameOrNil 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

- (void)viewDidLoad
{
    product2.text = @"Use Date Picker";

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (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