Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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 如何为self.typeOfAssetLabel.text设置KVC_Ios_Objective C_Kvc - Fatal编程技术网

Ios 如何为self.typeOfAssetLabel.text设置KVC

Ios 如何为self.typeOfAssetLabel.text设置KVC,ios,objective-c,kvc,Ios,Objective C,Kvc,我有一些UILabels连接到UIOutlet属性。我想通过KVC设置标签的文本属性,因为我将标签属性名称设置为字符串 因此,通常(无KVC)我会这样访问它们: self.typeOfAssetLabel.text = @"Hello"; 现在,在KVC中会是什么 我试过: [self.typeOfAssetLabel setValue:@"test" forKey:@"text"]; 这是有效的。但这样我就不能按字符串设置属性名typeOfAssetLabel 我想这应该行得通 [self

我有一些
UILabels
连接到
UIOutlet
属性。我想通过KVC设置标签的文本属性,因为我将标签属性名称设置为字符串

因此,通常(无KVC)我会这样访问它们:

self.typeOfAssetLabel.text = @"Hello";
现在,在KVC中会是什么

我试过:

[self.typeOfAssetLabel setValue:@"test" forKey:@"text"];
这是有效的。但这样我就不能按字符串设置属性名
typeOfAssetLabel

我想这应该行得通

[self setValue:@"test" forKey:@"typeOfAssetLabel.text"];
但这样我就得到了“不是键值complient…”错误。正确的方法是什么。

您想要的是:

[self setValue: @"test" forKeyPath: @"typeOfAssetLabel.text"];
诀窍是当路径中有多个键时,使用
forKeyPath
而不是
forKey