调用[polygonShapeView setNeedsDisplay]时;我没有调用我的polygonShapeView drawRect方法。我能够做polygonShapeView.hidden = YES,这工作正常,所以我有一个很好的参考视图,并已连接我的插座。有什么想法吗?
或者Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonShapeView.h"
@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *polygonShape;
IBOutlet PolygonShapeView *polygonShapeView;
IBOutlet UILabel *polygonLabel;
}
- (IBAction)decrease:(id)sender;
- (IBAction)increase:(id)sender;
- (void)awakeFromNib;
- (void)updateInterface;
@end
Controller.m或者
//
// Controller.m
//
// Created by Chris Muench on 6/24/11.
// Copyright 2011 N/A. All rights reserved.
//
#import "Controller.h"
@implementation Controller
- (IBAction)decrease:(id)sender
{
[polygonShape setNumberOfSides:numberOfSidesLabel.text.integerValue - 1];
[self updateInterface];
}
- (IBAction)increase:(id)sender
{
[polygonShape setNumberOfSides:numberOfSidesLabel.text.integerValue + 1];
[self updateInterface];
}
- (void)awakeFromNib
{
polygonShape = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
[self updateInterface];
}
- (void)updateInterface
{
[polygonShapeView setNeedsDisplay];
numberOfSidesLabel.text = [NSString stringWithFormat:@"%d",polygonShape.numberOfSides];
polygonLabel.text = polygonShape.name;
if (polygonShape.numberOfSides == polygonShape.maximumNumberOfSides)
{
increaseButton.enabled = NO;
}
else
{
increaseButton.enabled = YES;
}
if(polygonShape.numberOfSides == polygonShape.minimumNumberOfSides)
{
decreaseButton.enabled = NO;
}
else
{
decreaseButton.enabled = YES;
}
}
@end
答案 0 :(得分:2)
我只能猜测,但似乎您的polygonShapeView
没有以任何方式与polygonShape
相关联。所以它可能会画,但不是根据你期望的数据。
我认为在polygonShapeView.shape = polygonShape;
或awakeFromNib
中应该有类似updateInterface
的内容。