Louis Holley
Louis Holley

Reputation: 135

Using object from one class in another

I have a two UIViewControllers, on one of which I want a custom button to be displayed. I have written the code for this. I have also written the code for a popover segue to the other ViewController, and as both controllers belong to my 'ViewController' class, the button is also displayed on the second ViewController, which I do not want.

Obviously I can create another class and make my second ViewController a member of this class, however I want the code for my second ViewController to change the colour of the button in the first ViewController, so how can I use an object from my first class in the second class implementation file?

Upvotes: 2

Views: 218

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

I have a two UIViewControllers, on one of which I want a custom button to be displayed. I have written the code for this. I have also written the code for a popover segue to the other ViewController, and as both controllers are subclasses of my 'ViewController' class, the button is also displayed on the second ViewController, which I do not want.

Why don't you make few property private in first cass so that it doesn't get inherited.


Obviously I can create another class and make my second ViewController a member of this class, however I want the code for my second ViewController to change the colour of the button in the first ViewController, so how can I use an object from my first class in the second class implementation file?

Your main problem is to access object of ClassA from ClassB.

Here are a lot of ways, and answers here, to do :

Update a label through button from different view

Xcode - update ViewController label text from different view

Setting label text in another class

Set label on another view to stored NSDate

Upvotes: 3

Related Questions