iPhone如何将字符串传递给另一个视图标签?

发布于 2024-11-09 08:46:54 字数 683 浏览 0 评论 0原文

我的问题是如何将字符串传递给另一个视图标签?我尝试了很多例子,但仍然无法获得我传递的值。

这是我保存的数据。

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

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

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

    [self dismissModalViewControllerAnimated:YES];
}

这是我想显示的保存数据。

- (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];
}

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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千年*琉璃梦 2024-11-16 08:46:54

如果您在 SelectDate viewController 中设置了时间属性,以便可以在其他 viewController 中访问它。

//SelectDate.h

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

//SelectDate.m

@synthesize time;  

现在您可以像您一样在其他 ViewController 中使用时间。

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.

瑕疵 2024-11-16 08:46:54

要获取日期的 NSString 表示形式,您应该查看 NSDateFormatter

示例:

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

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];
浊酒尽余欢 2024-11-16 08:46:54

不要访问上一个视图,而是将数据传递到下一个视图:

嗨,我的问题是如何将字符串传递到另一个视图标签?我尝试了很多例子,但仍然无法获得我传递的值。

这是我保存的数据。

-(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];
}

这里是你想要显示的保存数据。

- (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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文