开发者

iPhone SDK. How to assign NSString to UILabel text?

开发者 https://www.devze.com 2023-01-01 17:21 出处:网络
If I have a class/object like this #import <Foundation/Foundation.h> @interface anObject : NSObject {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消