ahyong87
ahyong87

Reputation: 45

iphone how to pass string to another view label?

My problem is how to pass string to another view label? I got try so many example but still can not get the value where I pass.

here is I save the data.

-(IBAction)Save:(id)sender{
    timedata = [datePicker date];
    NSLog(@"timedata save is = %@",timedata);

    time = [NSString stringWithFormat:@"%@",timedata];

    NSLog(@"String time = %@",time);

    [self dismissModalViewControllerAnimated:YES];
}

here is I want to show the save data.

- (void) viewWillAppear:(BOOL)animated {

    show = [[SelectDate alloc]initWithNibName:@"SelectDate" bundle:nil];
    show.time = time;
    NSLog(@"time = %@",time);

    Selectime.text = show.time;
    NSLog(@"show.time = %@",show.time);     

    [super viewWillAppear:animated];
}

Upvotes: 1

Views: 1293

Answers (3)

rptwsthi
rptwsthi

Reputation: 10172

Instead of accessing last view, pass your data to your next view:

Hi,My problem is how to pass string to another view label? I got try so many example but still can not get the value where I pass.

here is I save the data.

-(IBAction)Save:(id)sender{
    timedata = [datePicker date];
    NSLog(@"timedata save is = %@",timedata);
    time = [NSString stringWithFormat:@"%@",timedata];
    NSLog(@"String time = %@",time);
    [self dismissModalViewControllerAnimated:YES];

    YourNextView *yourNextView=[[YourNextView alloc] init];
    yourNextView.anString=[NSString stringWithFormat:@"%@",timedata];
    [yourNextView release];
}

here is You want to show the save data.

- (void) viewWillAppear:(BOOL)animated {

    //show = [[SelectDate alloc]initWithNibName:@"SelectDate" bundle:nil];
    //show.time = time;
    //NSLog(@"time = %@",time);
    Selectime.text = self.anString;
    NSLog(@"show.time = %@",show.time); 
    [super viewWillAppear:animated];
}

Upvotes: 0

Nitish
Nitish

Reputation: 14113

If you have set property for time in SelectDate viewController so that it can be accessed in other viewControllers.

//SelectDate.h

NSString *time;  
// Your declarations  
@property(nonatomic,retain) NSString *time;  

//SelectDate.m

@synthesize time;  

Now you can use time in other ViewControllers like you are doing.

Upvotes: 1

Damo
Damo

Reputation: 12890

To get a NSString representation of a date you should look at NSDateFormatter

example:

NSDate* timedata = [datePicker date];   
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString *time = [dateFormat timedata];
[dateFormat release];

Upvotes: 0

Related Questions