Objective c setNeedsDisplay未更新接口
调用[polygonShapeView setNeedsDisplay]时;未调用我的polygonShapeView drawRect方法。我可以做polygonShapeView.hidden=是的,它工作得很好,因此我有一个很好的视图参考,并且已经连接了我的插座。有什么想法吗 控制器.hObjective c setNeedsDisplay未更新接口,objective-c,cocoa-touch,Objective C,Cocoa Touch,调用[polygonShapeView setNeedsDisplay]时;未调用我的polygonShapeView drawRect方法。我可以做polygonShapeView.hidden=是的,它工作得很好,因此我有一个很好的视图参考,并且已经连接了我的插座。有什么想法吗 控制器.h #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import "PolygonShape.h" #import
#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
我只能猜测,但您的polygonShapeView
似乎没有以任何方式链接到polygonShape
。所以它可能会画,但不是根据你期望的数据
我认为应该有类似于
polygonShapeView.shape=polygonShape
在awakeFromNib
中,或者在updateInterface
中,结果是我在awakeFromNib中创建了一个新的多边形形状,而不是使用我在nib中创建的多边形形状,这没有导致任何真正的更改。确切地说,因此没有连接。:)
//
// 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