質問

I have a pretty cluttered display where I need a textField, 9 UIlabels and 9 UIButtons with lines connecting them in a inverted-tree shape. Everything is created on code.

In order to tiddy up my UIViewController from display code such as constraints and everything display-realted, I've created a subclass of UIView. Inside this subclass of UIView I've created all the labels and buttons as public properties.

On Storyboard I changed the class of self.view to the new subclass I created. When I run the simulator it displays correctly what I wanted.

The problem comes when I try to access the public properties of the subclass I've created, for instance when I try to change a label's text. When I type on the viewController Xcode doesn't show all the properties I've set previously.

Now I don't know if my approach is straight-on wrong or if I'm missing something. Would it be better to create a subclass of UIViewController and work on from there?

Any help would be appreciated greatly.

役に立ちましたか?

解決

Override the view property in your interface extension:

#import "CustomView.h"

@interface ViewController ()

@property (nonatomic, strong) CustomView *view;

@end

@implementation ViewController

// Only needed if you're not using storyboards
-(void)loadView
{
    self.view = [CustomView new];

    // Setup the rest of your view, e.g.
    self.view.customLabel.text = @"Custom label text";
}

@end

EDIT: I've just noticed your using storyboards, so the loadView isn't needed, but I've left this in for completeness for others

他のヒント

You have to cast it to your view.like this

MyViewClass *MyView=(MyViewClass*)self.view;


if ([self.view isKindOfClass:[MyViewClass class]]) {

    //do something like MyView.urProperty 

    // Don't forget to import the MyViewClass.h in the class        

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top