Babiker
Babiker

Reputation: 18798

How to access custom class properties as a referenced outlet?

I have a view that has a reference outlet to a UIViewController called theView. This view uses a custom class which has a property named theStr. I can access theView from the UIViewController like: self.theView, however, I can not access the custom class properties like : self.theView.theStr I get error: Property 'theStr' not found on object of type 'UIVIew *'

Upvotes: 1

Views: 578

Answers (3)

Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27153

Seems like you have created custom view class and assigned it to the subview on the view of your view controller. I suppose that your custom view contains some element that you want to assign to the theStr property, but seems you have drag and dropped that instance to the view controller class. So right now your view controller has theStr IBOutlet property, but your custom view does not know about any theStr properties, because your custom view is a different object.

So you should think about your custom UIView object that you layout on your UIViewController view and add a property to your custom view instead of adding it to your view controller.

Just open your custom view class (.h file) and open your interface builder from where you can drag drop and assign theStr property in your custom view class.

Property 'theStr' not found on object of type 'UIVIew':

says that you really don't have any property with the theStr because seems you have assigned it not to a custom view but to view controller as I can suppose from your description.

Upvotes: 0

Babiker
Babiker

Reputation: 18798

  1. The outlet type must be of the same custom type of the referenced object.

  2. The custom class header must be imported.

Upvotes: 0

vichevstefan
vichevstefan

Reputation: 898

In the Interface Builder, select that view, and check Custom Class/Class section is correct in Identity Inspector.

Also, to access it's properties, you will need to include header file of custom class

Upvotes: 1

Related Questions