1

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];
}
Vladimir
  • 170,431
  • 36
  • 387
  • 313
ahyong87
  • 45
  • 10

3 Answers3

1

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.

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • i have add this oso.but still con not get the value. – ahyong87 May 24 '11 at 08:49
  • You can use a Data class instead. Check out [My Answer](http://stackoverflow.com/questions/6065965/how-to-define-a-global-variable-that-can-be-accessed-anywhere-in-my-application/6067515#6067515). Let me know if still you have problem. – Nitish May 24 '11 at 08:57
  • Where my answer has started, you'll see a tick mark. Just tick it. – Nitish May 24 '11 at 10:10
0

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];
Damo
  • 12,840
  • 3
  • 51
  • 62
0

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];
}
rptwsthi
  • 10,094
  • 10
  • 68
  • 109