views:

34

answers:

1

I'm some trouble adding strings together for a UITextView in my app. The method I've been using is this

(header)

#import <UIKit/UIKit.h>

@interface calculatorViewController : UIViewController {

    IBOutlet UITextView *output;
}

-(IBAction)b1;

@property(nonatomic, copy) NSString *output;

@end

(main)

#import "calculatorViewController.h"

@implementation calculatorViewController

-(void)b1 {
    [output stringByAppendingString:@"hi"];
}

The problem I've been having with this method is when I use the button the app crashes. The warning it gives me is 'UITextView' may not respond to '-stringByAppendingString:'
When I replace output with at string it works though and that confused me.

Any suggestions? Am I doing something wrong?

Thanks

+3  A: 

You are trying to treat an UITextView as if it was a NSString - that just doesn't work. You need to fix that property declaration and set the text for the text view correctly, e.g.:

output.text = [output.text stringByAppendingString:@"hi"];
Georg Fritzsche
Ok thanks for the advice that worked perfectly.
Jason