Mc.Lover
Mc.Lover

Reputation: 4994

Using one IBOutlet with different objects

I was wondering how is it possible that use ONE IBOutlet to several objects , for example I have IBOutlet UITextView *myText; then 3 UItextView on one view , so I want connect all of them with myText !

Upvotes: 0

Views: 765

Answers (4)

You can have one NSArray which you declare as an IBOutletCollection (instead of IBOutlet). In order to know what text field you are getting out of the array, you can set a tag on each one in IB and just pull from the array the text fields that match specific tags.

Upvotes: 2

Di Wu
Di Wu

Reputation: 6448

This is inappropriate. However, it's appropriate to hook one IBAction with multiple IBOutlets. So that when different buttons are pressed, they go to the same IBAction. And the IBAction can tell where on earth that triggering is coming from by looking at the (id)sender argument.

Upvotes: 1

WrightsCS
WrightsCS

Reputation: 50727

You can use 1 object and have different tags.

Upvotes: 1

cesarislaw
cesarislaw

Reputation: 1599

Don't think so. Each UITextView in the one view would be a separate instance of the UITextView class. The myText variable would only be able to point to one instance's memory address at a time.

I'm not sure what you're attempting to accomplish but you might be able to 'fake it' by having all the UITextViews use the controller as their delegate and setting their properties equal to each other when ever changes are detected. (i.e. Every time the controller receives a message about the text property changing it sets all the UITextView objects text properties equal to the changed UITextView's text property).

Upvotes: 1

Related Questions