如何为数组中的特定字符串设置属性字符串?

时间:2014-07-09 19:12:58

标签: ios objective-c arrays cocoa-touch

我有一个数组,它将一组字符串传递给tableViewController,然后传递给detailViewController。我希望能够在最终的detailViewController上更改所选数组的属性。在最后的detailViewController上我有:

NSDictionary *redAttrs = @{NSForegroundColorAttributeName:[UIColor redColor]};
NSDictionary *greenAttrs = @{NSForegroundColorAttributeName:[UIColor greenColor]};
[_WhatString setAttributes:redAttrs range:NSMakeRange(6, 5)];
[_WhatString setAttributes:greenAttrs range:NSMakeRange(20, 5)];

_WhatString = _DetailModal[2];
_WhatLabel.attributedText = _WhatString;

其中_DetailModal是数组,特定数组项(我想编辑的字符串)位于[2]位置。每个数组项的编辑都是相同的,所以我不需要担心动态更改它。这个代码应该在最终的detailViewController上,还是应该在我第一次声明和指定数组时实现?

这是正确的方法吗? 当我尝试加载detailViewController页面时,我发现'无法识别的选择器发送到实例' 错误。会导致这种情况的原因是什么?

0 个答案:

没有答案