0

I'm trying to access an IBOutlet from my other view controller, I have tried importing them both;

#import "CreateTest.h" #import "SecondViewController.h" But when I try to access the IBOutlet; _SubjectValue.text = @"hi"; It returns an error saying "Use of undeclared identifier _SubjectValue"

jscs
  • 63,694
  • 13
  • 151
  • 195
  • If you're trying to access one view controller IBOutlet from another view controller this is not a good practice and proper way. Check out [this](http://stackoverflow.com/questions/28344336/how-to-access-an-iboutlet-from-another-class) everything is well explained – Mahbub Ahmed Mar 12 '17 at 17:10
  • Mine is objective-c, not swift –  Mar 12 '17 at 17:14
  • I know but the basic is same . And for class check out my answer bellow .. – Mahbub Ahmed Mar 12 '17 at 17:14

2 Answers2

0

Make first class to delegate of second class. Then define IBOUTLET in delegate protocol. Then access it via delegate like so:

_delegate.yourIBOutlet.someProperty

If your very new I'd recommend some basic tutorials.

Edit: An instance of second class is required though. Depending if you're working with storyboard or not you ca receive/instantinate it in different ways.

Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
-1

If you are trying to access another class IBoutlet, first you have to create object of that class.

You're trying to access IBOutlet like this _SubjectValue.text = @"hi"; which basically means self.SubjectValue.text = @"hi"; but you'r second class don't have a IBOutlet name SubjectValue.text.

You have to access IBOutlet of another class through its object.Create a object of the class and then use this object to access the property/IBOutlet of that class

Hope it helps..

Mahbub Ahmed
  • 196
  • 1
  • 8