Nguyen  Minh Binh
Nguyen Minh Binh

Reputation: 24433

how to connect an IBOutlet to textview control in iOS?

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?

Currently, I have declare an IBTextView as below:

HelloViewControler.h file:

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

HelloViewControler.m:

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

}

Code to update a string to textview control:

    txtTextMe.text = @"Button clicked";

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

Upvotes: 1

Views: 5418

Answers (3)

Nguyen  Minh Binh
Nguyen Minh Binh

Reputation: 24433

This is my fault. I drag a UITextField to *.xib file but I declare an IBTextView in my code. Thanks all.

Upvotes: 0

nicktones
nicktones

Reputation: 863

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.

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.

Your Second iOS App: Storyboards

Upvotes: 4

Martin Kenny
Martin Kenny

Reputation: 2498

  1. Right-click on the textview control in the NIB file. A HUD-style menu should appear.

  2. Under "Referencing Outlets", drag from the circle to the right of "New Referencing Outlet" to "File's Owner" in the "Placeholders" section to the left. When you release the mouse button, another popup menu should appear.

  3. Pick txtTextMe from the menu.

  4. Build and enjoy :-)

Upvotes: 2

Related Questions