views:

241

answers:

2

I am having trouble copying the value of an NSString into a Textfield value. I've done this before, but for some reason it's not working in the function below. Can someone tell me if I'm doing something wrong?

pictureComment is the Textfield and comment is an NSString. When I look at the log file, only 'comment' prints. Any suggestions?

-(void) userPhotoComment:(PhotoComment*)userPhotoComment
    didAddComment:(NSString*)comment
{
NSLog(@"PhotoPicker-DidAddComment: Below is the comment");
NSLog(comment);     // this prints the comment correctly
pictureComment.text = [comment copy];

NSLog(@"PhotoPicker-DidAddComment: Below is the picture comment");
NSLog(pictureComment.text);     // doesn't print

[self dismissModalViewControllerAnimated:YES];
    /// ... more stuff is done below
}
+1  A: 

Perhaps this is too simple, but have you made sure that pictureComment is not nil? Should it be userPhotoComment instead?

Justin Gallagher
+1  A: 

There's no need to copy the comment into the pictureComment field - in fact, your code as it stands has a memory leak.

The NSLogs might not be working because you're using NSLog incorrectly - you should never directly NSLog a variable. Try this version of the method (making sure pictureComment isn't nil):

-(void) userPhotoComment:(PhotoComment*)userPhotoComment
           didAddComment:(NSString*)comment
{
NSLog(@"PhotoPicker-DidAddComment: Below is the comment");
NSLog(@"%@", comment);     // this prints the comment correctly
pictureComment.text = comment;

NSLog(@"PhotoPicker-DidAddComment: Below is the picture comment");
NSLog(@"%@", pictureComment.text);     // doesn't print

[self dismissModalViewControllerAnimated:YES];
/// ... more stuff is done below

}

iKenndac
Using NSLog with NSString as an argument is certainly no problem.
nschmidt
@nschmidt. Sure. But that doesn't mean that you should use it. Creating a formatted string is the way to do it.
Abizern
Xcode 3.1 and up will issue a warning for `NSLog` statements that are not formatted.
Alex Reynolds