【发布时间】:2011-05-11 20:54:50
【问题描述】:
到目前为止,我的代码工作正常,但我必须为 UIView 创建一个类。这有点不方便,因为我也需要与 ViewController 交互。
顺便说一句,我确实在UIViewController 子类文件的ViewDidLoad 上尝试了[self setNeedsDisplay],但没有成功。
这是代码,它适用于 UIView 子类,但不会在 UIViewController 上调用:
- (void)drawRect:(CGRect)rect
{
UIColor *currentColor = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
someNum = 1;
CGContextBeginPath(context);
CGContextMoveToPoint(context, 30, 40);
[self addDotImageX:30 andY:40];
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextStrokePath(context);
}
有什么想法可以尝试吗?顺便说一句,这是一个 TabBar 应用程序。我知道那些会以某种方式阻止对drawRect 的调用。
以编程方式创建的选项卡,而不是通过 Nib。例如:
NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
UIViewController *vc;
vc = [[Education alloc] init];
vc.title = @"Education";
[listOfViewControllers addObject:vc];
vc.tabBarItem.image = [UIImage imageNamed:@"info.png"];
[vc release];
我会很感激任何想法。我已经浏览了这个网站上与setNeedsDisplay 不调用drawRect 相关的答案,并且没有找到适合我的特殊情况的答案。
谢谢。
【问题讨论】:
标签: objective-c cocoa-touch ios uiview uiviewcontroller