Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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_Nsstring_Nsnotificationcenter - Fatal编程技术网

Ios 通知和字符串

Ios 通知和字符串,ios,objective-c,nsstring,nsnotificationcenter,Ios,Objective C,Nsstring,Nsnotificationcenter,我正在将一个类中的字符串传递给视图控制器类中的UILabel。由于某些原因,无法传递字符串。当我检查字符串中的内容时,它是0x0 m班 [[NSNotificationCenter defaultCenter] postNotificationName:@"notification" object:self]; somestring = @"..."; ViewController.m [

我正在将一个类中的字符串传递给视图控制器类中的
UILabel
。由于某些原因,无法传递字符串。当我检查字符串中的内容时,它是0x0

m班

[[NSNotificationCenter defaultCenter] postNotificationName:@"notification"
                                                    object:self];

somestring = @"...";
ViewController.m

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleData:)
                                             name:@"notification"
                                           object:nil];

}
- (void)handleData:(NSNotification *)notification {


[[NSOperationQueue mainQueue] addOperationWithBlock:^{

    self.timerLabel.text =somestring;

}];
}

您似乎有一些问题:

我不确定您为什么在
self.class.somestring
中使用
class
,我希望它只是
self.somestring
。如果您添加了一个类方法,那么命名和意图很差

通知对象是控制器实例,因此,使用
self.class.somestring=notification.object将存储该控制器实例。不是一串。因此,当您稍后执行
lableinthisclass.text=self.class.somestring您将控制器实例视为字符串并获得异常


考虑类交互是否正确,并在代码需要字符串的地方使用字符串。

libc++abi.dylib:以NSException类型的未捕获异常终止-断点位于label.text=class.somestring检查.xib文件中的标签连接标签连接在情节提要和中。h:@属性(非原子,强)IBUILabel*标签;但是您在代码中提到了标签名“lableinthisclass”吗?请勾选OK,那么
n异常中给出的原因是什么?
?好的,谢谢。删除通知对象停止了异常。我已更新代码,即使将字符串指定给未更新的文本,也会显示该异常。谢谢。
字符串为0x0
=>这意味着字符串为
nil
,因此不包含任何内容。。。