user1566244
user1566244

Reputation: 3

How to subclass a subclass of UIViewController with xib

I am working on a game. The game has different levels but share the same methods. I was thinking about subclassing the main game class.

How can i subclass the main game class(the main game class is a subclass of viewcontroller with xib)? Can i overrider the xib with subclass's xib?

//my main game class.
@interface Game : UIViewController{

//subclass
import <UIKit/UIKit.h>
import "Game.h"

@interface level1 : Game {

}

when i used level1.view, it gave me an error"accessing unknown view class method)

It it is impossible, how can i create a game with different levels~~ thanks

Upvotes: 0

Views: 324

Answers (2)

Jeffery Thomas
Jeffery Thomas

Reputation: 42588

accessing unknown view class method

This looks like you are calling [level1 view]. This is an attempt to call a class method name +view. There is no such class method. You are attempting to get to an instance method name -view.

level1 *myLevel1 = [[level1 alloc] initWithNibName:nibName bundle:nibBundle];
myLevel1.view;

BTW: It is the usual practice to have a capital letter begin a class. So the class name should be Level1 not level1.

Upvotes: 1

jerrylroberts
jerrylroberts

Reputation: 3454

One approach is to create layers on your view for each level.

Upvotes: 0

Related Questions