iPhone SDK. How to assign NSString to UILabel text?
If I have a class/object like this
#import <Foundation/Foundation.h>
@interface anObject : NSObject {
NSString *aProp;
}
@property NSString aProp;
@end
and in the cellForRowAtIndexPath method i want to assign one of the string values from its properties to a uilabel of a tableviewcell, how do i do it?
I've tried this but it doesn't work
[[cell topLabel] setText:(NSString *)anObject.aProp];
Putting a breakpoint on the above line and inspecting it, the debugger says "variable is not a CFString
Casting the property to a CFString doesnt work Modifying the class and declaring the property as a CFS开发者_如何转开发tringRef doesnt work either
cell.textLabel.text = @"Foo";
This is the proper way to declare the property:
@property (nonatomic, copy) NSString * aProp;
note: the issue was with your "NSString aProp" not being a pointer. and, yes, as frog suggested, copy is more appropriate.
精彩评论