如何将 IBOutlet 连接到 iOS 中的 textview 控件? [英] how to connect an IBOutlet to textview control in iOS?

查看:38
本文介绍了如何将 IBOutlet 连接到 iOS 中的 textview 控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是 iOS 新手,不知道如何将 UITextView 对象连接到 *.xib 文件上的 textview 控件?有没有办法在iOS上为控件设置唯一ID?

I'm really a newbie on iOS and I don't know how to connect the UITextView object to the textview control on *.xib file? Is there any way to set the unique ID to a control on iOS?

目前,我已经声明了一个 IBTextView 如下:

Currently, I have declare an IBTextView as below:

HelloViewControler.h 文件:

HelloViewControler.h file:

@interface HelloViewController : UIViewController{
   IBOutlet UITextView *txtTextMe;
}
@property (retain,atomic) UITextView *txtTextMe;
- (IBAction)buttonPressed:(id)sender;
@end

HelloViewControler.m:

HelloViewControler.m:

@synthesize txtTextMe;
- (IBAction)buttonPressed:(id)sender{
    txtTextMe.text = @"Button clicked";

}

将字符串更新为 textview 控件的代码:

Code to update a string to textview control:

    txtTextMe.text = @"Button clicked";

没有错误.但是当我运行代码时,字符串Button Clicked"没有更新到文本视图中.

No Error. But when I run the code, the string "Button Clicked" wasn't updated to the textview.

推荐答案

按住 CTRL 键并单击并从 .xib 中的项目拖动到代码中.这将创建一个 IBOutlet 或 IBAction(您通过弹出窗口选择)并将其链接到 .xib 上的对象.

Hold CTRL and click and drag from the item in the .xib into the code. This will create either an IBOutlet or IBAction (you chose via popup) and link it to the object on the .xib.

如果您已经创建了代码,也可以通过左侧检查器来完成.

It can also be done via the left hand inspector if you have already created the code.

如果您不熟悉 iOS 编程和 Xcode,我强烈建议您查看开发者门户上的 Apple 教程.他们有一些出色的介绍性指南,并附有分步说明.第二篇涵盖了故事板的使用,是对故事板、Xcode 和 iOS SDK 的非常棒的介绍 - 链接如下.

If you are new to iOS programming and Xcode I would very strongly recommend you look at Apple's tutorials on the developer portal. They have some excellent introductory guides with step by step instructions. The second one covers using storyboards and is a really great introduction to storyboards, Xcode and the iOS SDK - link below.

你的第二个 iOS 应用:故事板

这篇关于如何将 IBOutlet 连接到 iOS 中的 textview 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆