在 UITextView 内部连接 NSString
我在应用程序中为 UITextView 添加字符串时遇到了一些麻烦。我一直在使用的方法是这个
(标题)
#import <UIKit/UIKit.h>
@interface calculatorViewController : UIViewController {
IBOutlet UITextView *output;
}
-(IBAction)b1;
@property(nonatomic, copy) NSString *output;
@end
(主要)
#import "calculatorViewController.h"
@implementation calculatorViewController
-(void)b1 {
[output stringByAppendingString:@"hi"];
}
我使用此方法遇到的问题是当我使用按钮时应用程序崩溃。它给我的警告是“UITextView”可能不会响应“-stringByAppendingString:”
当我用 at 字符串替换输出时,它仍然有效,这让我很困惑。
有什么建议吗?我做错了什么吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您试图将
UITextView
视为NSString
- 这是行不通的。您需要修复该属性声明并正确设置文本视图的文本,例如:You are trying to treat an
UITextView
as if it was aNSString
- that just doesn't work. You need to fix that property declaration and set the text for the text view correctly, e.g.: