具有UIView继承类的UIViewController,编程
问题描述:
我正在使用一个库,它是从UIView继承的类。我如何以编程方式创建使用此类的UIViewController,而不是普通的UIView?具有UIView继承类的UIViewController,编程
的视图控制器的.h文件中看起来如下:
#import <UIKit/UIKit.h>
#import "PLView.h"
@interface HelloPanoramaViewController : UIViewController {
IBOutlet PLView * plView;
}
@property (nonatomic, retain) IBOutlet PLView *plView;
@end
.m文件如下:
#import "HelloPanoramaViewController.h"
@implementation HelloPanoramaViewController
@synthesize plView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do stuff here...
}
- (void)dealloc
{
[plView release];
[super dealloc];
}
@end
然后我就应该用笔尖,让“plView变量指向视图”。 但是,如果不使用Interface Builder,我将如何以编程方式执行此操作?我怎么能让这个UIViewController创建一个PLView,而不是一个UIView?
答
在您创建的viewController,还可以创建自定义视图的一个实例,然后该视图设置为您控制器的观点的地方:
HelloPanoramaViewController *controller = [[HelloPanoramaViewController alloc] init];
PLView *view = [[PLView alloc] init];
controller.view = view;
答
UIViewController中会的东西,看起来像
#import "HelloPanoramaViewController.h"
@implementation HelloPanoramaViewController
- (void)loadView
{
self.view = [PLView plview]//or whatever it takes to create the plview.
}
- (void)viewDidLoad
{
//create more objects
}
- (void)viewDidUnload
{
//release unwanted objects that were created viewDidLoad
}
-(void) dealloc
{
// release all
[super dealloc];
}
@end
的详细信息... here
仅供参考,如果你不知道,你其实可以做IB,以及通过改变你的主要的“类”属性UIView在你的笔尖是所需的类名。 – occulus 2011-03-07 17:35:43