起初我绘制图形:
-(void)drawRect: (CGRect)rect{
//Circle
circle = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(circle, [UIColor darkGrayColor].CGColor);
CGContextFillRect(circle,CGRectMake(10,10, 50, 50));
//rectangle
rectangle = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(rectangle, [UIColor darkGrayColor].CGColor);
CGContextFillRect(rectangle, CGRectMake(10, 10, 50, 50));
//square
square = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(square, [UIColor darkGrayColor].CGColor);
CGContextFillRect(square, CGRectMake(100, 100, 25, 25));
//triangle
triangle = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(triangle, [UIColor darkGrayColor].CGColor);
CGPoint points[6] = { CGPointMake(100, 200), CGPointMake(150, 250),
CGPointMake(150, 250), CGPointMake(50, 250),
CGPointMake(50, 250), CGPointMake(100, 200) };
CGContextStrokeLineSegments(triangle, points, 6);
}
现在我想将图形放入一个数组中:
-(void)viewDidLoad {
grafics = [[NSMutableArray alloc]initWithObjects: circle,rectangle,square,triangle];
[self.navigationItem.title = @"Shape"];
[super viewDidLoad];
}
问题是,我必须进行强制转换,从而使对象适合该数组。另一个问题是 UITableViewController 不会将数组加载到行中。tableview 没有问题,但处理 CGContext 失败。我做错了什么?