如何设置两个viewController之间的接口方法以在导航控制器中传递参数

发布于 2024-08-29 00:02:26 字数 798 浏览 3 评论 0原文

我创建了基于窗口的应用程序,根控制器作为选项卡栏控制器。一个选项卡栏有导航控制器。

导航控制器的ViewController实现,我正在推Viewcontroller。

我希望将参数从导航控制器的视图控制器传递到推送视图控制器。

我尝试按照以下方法通过。

//ViewController.h
@interface ViewController:UIViewController{
   NSString *String;
}
@property(copy, nonatomic)NSString *String;
@end
//ViewController.m 
 #import "ViewController1.h"

 ViewController1 *level1view = [[ViewController alloc]init];
 level1view.hideBottomBarWhenPushed = YES;
 level1view.theString = String;
 [self.navigationController pushViewController:level1view animated:YES];
 [level1view release]; 

//ViewController1.h
NSString *theString;

@property(copy, nonatomic)NSString *theString;

这工作正常。但我想传递多个参数,例如 Integer 和 UITextFiled Values,那么如何做到这一点?

有什么苹果文档可以让我了解这件事吗?

谢谢,

I have created Window based application, root controller as Tab Bar controller. One Tab bar has Navigation controller.

Navigation controller's ViewControlller implementation, I am pushing Viewcontroller.

I am looking to pass parameter from Navigation Controller's View controller to pushed View Controller.

I have tried to pass as per below method.

//ViewController.h
@interface ViewController:UIViewController{
   NSString *String;
}
@property(copy, nonatomic)NSString *String;
@end
//ViewController.m 
 #import "ViewController1.h"

 ViewController1 *level1view = [[ViewController alloc]init];
 level1view.hideBottomBarWhenPushed = YES;
 level1view.theString = String;
 [self.navigationController pushViewController:level1view animated:YES];
 [level1view release]; 

//ViewController1.h
NSString *theString;

@property(copy, nonatomic)NSString *theString;

This is working fine. but I want to pass more than one parameter like Integer and UITextFiled Values so how to do that?

Is there any Apple Doc that I can get idea about this?

Thanks,

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

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

发布评论

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

评论(2

远山浅 2024-09-05 00:02:26

也许使用 NSUserDefaults 代替,就像:

    NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
[UserDefaults setInteger:... forKey:@"KEY"];

在另一个控制器中:

    NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
...= [UserDefaults integerForKey:@"KEY"];

Maybe use NSUserDefaults instead, just like:

    NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
[UserDefaults setInteger:... forKey:@"KEY"];

and in the other controller:

    NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
...= [UserDefaults integerForKey:@"KEY"];
一念一轮回 2024-09-05 00:02:26

你必须像这样一项一项地传递它,但要确保你在

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

这一行之后全部传递......否则有时它不会反映

所以交换

level1view.theString = String; 
[self.navigationController pushViewController:level1view animated:YES]; 

[self.navigationController pushViewController:level1view animated:YES]; 
level1view.theString = String;

you have to pass it one by one like this only but make sure that you pass it all after

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

this line... Otherwise sometimes it won't reflect

So interchange

level1view.theString = String; 
[self.navigationController pushViewController:level1view animated:YES]; 

to

[self.navigationController pushViewController:level1view animated:YES]; 
level1view.theString = String;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文