Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 使用Segue从UIViewController传输字符串_Ios_Objective C_Uiviewcontroller_Segue - Fatal编程技术网

Ios 使用Segue从UIViewController传输字符串

Ios 使用Segue从UIViewController传输字符串,ios,objective-c,uiviewcontroller,segue,Ios,Objective C,Uiviewcontroller,Segue,我正在做以下工作: #ViewController1.m - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSLog(@"Transferring"); guestViewController *controller = [segue destinationViewController]; [controller.label isEqualToString:self.num_val

我正在做以下工作:

#ViewController1.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   NSLog(@"Transferring");

   guestViewController *controller = [segue destinationViewController];
   [controller.label isEqualToString:self.num_value.text];
}
但是,当加载视图时,文本不会贯穿或显示在标签中。我在过去的程序中做过这项工作,它在Xcode 4上工作过。然而,由于某些原因,在Xcode 5中它对我不起作用。我是否还需要实现其他东西才能在Xcode中工作

[controller.string isEqualToString:self.num_value.text];
isEquelToString
唯一检查的是
controller.string
是否与
self.num.value.text相同。

- (BOOL)isEqualToString:(NSString *)aString
返回一个布尔值,该值指示给定字符串是否相等 使用基于Unicode的文本比较发送到接收器

阅读

您可以将字符串传递给另一个控制器,如下所示:

guestViewController的
h文件中:

@property (nonatomic, strong) NSString *theStringWhatYouWantToGet;
prepareForSegue
中:

controller.theStringWhatYouWantToGet  = self.num_value.text;

将此项添加到
guestViewController的头文件中:

@属性(非原子,强)NSString*值

您的
prepareforsgue
方法如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   NSLog(@"Transferring");

   guestViewController *controller = [segue destinationViewController];
   [controller setValue : self.num_value.txt];
}
isEqualToString
用于比较!不用于指定值

然后在
viewDidLoad
方法中,添加以下内容:


[textlab setText:value][controller.string IsequalString:self.num_value.text]编码>

您只是比较这两个字符串,没有为其分配任何内容anything@micantox所以您建议我将其更改为“controller.label.text=self.num\u value.text”?是的<代码>isEqualToString
用于比较!不要赋值!等等,否您不能在打开视图之前将文本指定给标签loaded@Zack-看看我的答案。那么标签的值只能通过字符串传输到视图控制器?我不能将值从一个标签转移到另一个标签?你可以。您可以看到,重要的是属性类型。您可以在guestViewController中声明UILabel属性。然后你可以说
[controller setLabel:self.myLabel]
@Zack-我回答了你的问题吗?是的,但在选择正确答案之前,让我在电脑上试试!对但请尝试传递NSString值,而不是UILabel。