@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SecondViewController *svc=[segue destinationViewController];
if ([segue.identifier isEqualToString:@"show"]) {
svc.scrool=@"dict";
}
}
- (IBAction)buttonAction:(id)sender {
dict= @{@"firstname":@"firstname.textfield.text", @"lastname":@"lastname.textfield.text", @"fullname":@"fullname.textfield.text",@"gender":@"gender.textfield.text",@"country":@"country.textfield.text",@"state":@"state.textfield.text",@"phnumber":@"phnumber.textfield.text",@"email":@"email.textfield.text",@"zipcode":@"zipcode.textfield.text",@"landnumber":@"landnumber.textfield.text"};
}
你能不能请任何人给我答案,因为这些需要使用 segues 将这些字典发送到另一个 View Controller
最佳答案
进行此更改:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SecondViewController *svc=[segue destinationViewController];
if ([segue.identifier isEqualToString:@"show"]) {
svc.scrool = dict;
}
}
在您的代码中,您传递的是值为“dict”的字符串,而不是您的 dict 变量。
编辑: 我还想在此代码中添加:
dict= @{@"firstname":@"firstname.textfield.text", @"lastname":@"lastname.textfield.text", @"fullname":@"fullname.textfield.text",@"gender":@"gender.textfield.text",@"country":@"country.textfield.text",@"state":@"state.textfield.text",@"phnumber":@"phnumber.textfield.text",@"email":@"email.textfield.text",@"zipcode":@"zipcode.textfield.text",@"landnumber":@"landnumber.textfield.text"};
您实际上并没有从文本字段中提取值。鉴于您已正确设置所有这些属性,您将需要使用:
dict= @{@"firstname": firstname.textfield.text, @"lastname": lastname.textfield.text, @"fullname": fullname.textfield.text, @"gender": gender.textfield.text, @"country": country.textfield.text, @"state": state.textfield.text, @"phnumber": phnumber.textfield.text, @"email": email.textfield.text, @"zipcode": zipcode.textfield.text, @"landnumber": landnumber.textfield.text};
还要确保在 SecondViewController 的 .h 文件中有 scrool
属性:
@property (strong, nonatomic) NSDictionary *scrool;
哇,好久没写 Obj-c 代码了,哈哈
关于ios - 如何使用 segues 将字典数据从一个 View Controller 发送到另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43781942/