在 UITextView 内部连接 ​​NSString

发布于 2024-09-05 22:57:06 字数 618 浏览 0 评论 0原文

我在应用程序中为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-09-12 22:57:06

您试图将 UITextView 视为 NSString - 这是行不通的。您需要修复该属性声明并正确设置文本视图的文本,例如:

output.text = [output.text stringByAppendingString:@"hi"];

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"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文