Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在两个视图控制器之间传递数据_Ios_Objective C_Iphone_Cocoa Touch_Uiviewcontroller - Fatal编程技术网

Ios 在两个视图控制器之间传递数据

Ios 在两个视图控制器之间传递数据,ios,objective-c,iphone,cocoa-touch,uiviewcontroller,Ios,Objective C,Iphone,Cocoa Touch,Uiviewcontroller,我有两个视图控制器叫DataPass和ViewController。我想将数据从DataPass传递到ViewController。我在ViewController中有一个标签,我在ViewController中有一个UIButton,它会自动关闭,而关闭时会将数据传递给DataPass中的标签 我做不到。请帮忙。这是我的密码: ViewController.h @interface ViewController : UIViewController - (IBAction)sayfaGec:(

我有两个视图控制器叫DataPass和ViewController。我想将数据从DataPass传递到ViewController。我在ViewController中有一个标签,我在ViewController中有一个UIButton,它会自动关闭,而关闭时会将数据传递给DataPass中的标签

我做不到。请帮忙。这是我的密码:

ViewController.h

@interface ViewController : UIViewController
- (IBAction)sayfaGec:(id)sender;
@property (retain, nonatomic) IBOutlet UILabel *label;
+(ViewController *)hop;
ViewController.m

+(ViewController *)hop{
    static ViewController *myInstance = nil;
    if (myInstance == nil){
        myInstance = [[[self class]alloc]init];
        myInstance.label.text = @"test";
    }
    return myInstance;
}
DataPass.h

- (IBAction)sayfaKapat:(id)sender;
DataPass.m

- (IBAction)sayfaKapat:(id)sender {
    [ViewController hop].label.text = @"ddsg";
    [self dismissModalViewControllerAnimated:YES];
}
在数据传递中,您说:

ViewController *vContr = [[ViewController aloc]init];
[vContr setLabelData: @"asta la vista baby!"];
[self.view addSubview:vContr.view];

问题是什么?如果没有更多的代码,很难说为什么这不起作用。是否取消工作,只是将文本分配给标签失败?也许IB中的标签没有正确连接?@ErikH。是的,问题只是将文本分配给标签失败。我是IOS开发的新手。我从不在控制器之间传递数据。但是标签、按钮和视图控制器之间的所有连接都是正确的。检查此链接的可能重复项它应该可以工作:创建ViewController对象后,您可以访问它声明的所有实例方法。检查标签的插座是否正确连接在xib?我正在使用故事板。不是xib文件。在故事板中,您应该看到viewController的控制器。您必须将插座挂接到标签上,否则它将不起作用。顺便问一下,您是通过编程方式创建标签的吗?我用鼠标左键将其拖动到.h文件中创建的。
ViewController *vContr = [[ViewController aloc]init];
[vContr setLabelData: @"asta la vista baby!"];
[self.view addSubview:vContr.view];