Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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_Uiviewcontroller_Nsstring - Fatal编程技术网

Ios 字符串赋值不起作用

Ios 字符串赋值不起作用,ios,uiviewcontroller,nsstring,Ios,Uiviewcontroller,Nsstring,我想在两个viewcontroller之间传递一个字符串,但始终为(null) 我的代码 GridViewController.h #import <UIKit/UIKit.h> @interface GridViewController : UIViewController { } @property (nonatomic, strong)UILabel * labelTitle; @end 在为labelTitle分配文本时,它不存在任何实例。标签从xib实例

我想在两个viewcontroller之间传递一个字符串,但始终为(null)

我的代码

GridViewController.h

 #import <UIKit/UIKit.h>

 @interface GridViewController : UIViewController {

 }

 @property (nonatomic, strong)UILabel * labelTitle;

 @end

在为labelTitle分配文本时,它不存在任何实例。标签从xib实例化,只有这样它才能保存该值

labeltitle
GridViewController
的GUI元素,当您尝试在其他类中访问时,它不会得到任何值,您最好尝试在
GridViewController
中创建一个
NSString
,并将该值分配给其他类中的该字符串,但是,当您为
GridViewController
加载
viewDidLoad
时,请将此字符串指定给标签,如下所示

-(void)viewDidLoad{

    [super viewDidLoad]; 
    self.labelTitle.text=self.stringYouCreated;

}
   grid.stringYouCreated = currow;
ViewController.m
中,将值指定给在
GridViewcontroller
中创建的字符串属性,如下所示

-(void)viewDidLoad{

    [super viewDidLoad]; 
    self.labelTitle.text=self.stringYouCreated;

}
   grid.stringYouCreated = currow;

您的
labelTitle
似乎为零。它应该是在
GridViewController

grid.labelTitle的
viewDidLoad
方法中创建的。在执行grid.labelTitle.text=currow时,labelTitle为零;我添加grid.labelTitle=[[UILabel alloc]init];在这个方法中,现在可以工作了。非常感谢你