Jason
Jason

Reputation: 91

Concatenating NSString inside of UITextView

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

Upvotes: 1

Views: 1736

Answers (1)

Georg Fritzsche
Georg Fritzsche

Reputation: 98974

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"];

Upvotes: 3

Related Questions