views:

595

answers:

2

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 CFStringRef doesnt work either

A: 
cell.textLabel.text = @"Foo";
Shaggy Frog
and how does @"Foo" relate to my object's property?do you mean cell.textLabel.text = @anOject.aProp; ??
Del
warning: passing argument 1 of 'setText:' from incompatible pointer type
Del
This is directly answering your question, "i want to assign one of the string values from its properties to a uilabel of a tableviewcell, how do i do it?". The important part is not the right-side `@"Foo"` bit, it's the left-side `cell.textLabel.text` bit, because *that's how you change the text of a UILabel of a UITableViewCell*.
Shaggy Frog
Finally got it working, reverted back to NSString's and set the property to (copy) as per Shaggy Frog's recommendationAnObject *obj = (AnObject *)[listData objectAtIndex:indexPath.row]; cell.topLabel.text = obj.aProp;
Del
Gotta love the negs (I can guess from whom) for a correct answer.
Shaggy Frog
+2  A: 

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.

eric
-1 for mentioning `NSString` property with `retain`, just after someone else did.
Shaggy Frog
ouch! I am new, trying to help, and pulled a few things together. this is the answer, not spread among 3 responses... thanks for the support
eric
OH... AND... I must add, If I could give you a -1, I would! You not only did not bother to actually answer the question, you got snippy about it, and missed his error completely. retain vs. copy was NOT at issue, the missing "*" WAS! Will someone please tell me this is not indicative of stackoverflow? If it is, I will be leaving now.
eric
eric, you got a -1 for giving bad advice, that also was unrelated to the question at hand. If you aren't sure about your answer, don't speculate, to avoid the negs. You'd also be wise to read through answers already posted before posting your own, especially if you're just going to echo what someone else (improperly) posted.
Shaggy Frog
all in all, a very disappointing experience frog... you are still missing the point completely.
eric
I think you are missing the point, actually, so I guess we're at an impasse.
Shaggy Frog
@Ross nearly all my reputation comes from answering questions. Next time you want to flame someone, you should be sure of facts like that first.
Shaggy Frog
BTW, most of the time when you get downvoted for incorrect answers (which is how SO works), you won't know why, because it's easier to just do so anonymously. I did the courtesy of explaining my downvote. I will forgo that courtesy for you in the future.
Shaggy Frog
I've deleted my previous comments, as I believe everyone who isn't blinded by their own ego's got it the first or second time. Your "polite" rudeness is not interesting. I, frankly, don't care what you do.
eric