ViewController和drawRect [英] ViewController and drawRect

查看:132
本文介绍了ViewController和drawRect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIViewController,我想调用drawRect,所以我可以绘制视图,但没有任何反应。

I have a UIViewController and I would like it to call drawRect so i can draw on the view but nothing happens.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
...code...
}

@end

和实现

#import "ViewController.h"


@implementation ViewController

-(void) drawRect:(CGRect) rect {
draw a pony
}

- (void)viewDidLoad {
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

应用程序运行时的视图,我做错了什么?

But no pony gets drawn on the view when the app is run, what do i do wrong?

推荐答案

UIViewController 没有覆盖消息 drawRect
您应该创建自 UIView 派生的自定义类,并覆盖 drawRect

The UIViewController don't have overridden message drawRect. You should create custom class derived from UIView and override message drawRect there.

您可以为 UIViewController 覆盖(UIView *)视图 UIView 或在Interface Builder中将类从 UIView 更改为自己的类。

You can override message (UIView *)view for UIViewController and return own custom UIView or in Interface Builder change class from UIView to own class.

这篇关于ViewController和drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆