我下面 iPhone开发的课程 从斯坦福大学开放大学,和我已经封锁了2天 assignment3, 也许有人可以帮我在这里?

任务是:

  1. 创建一个自定义的)子类,这将显示你的PolygonShape对象
  2. 给你看类访问PolygonShape对象,以便它可以检索的细节面需要

问题是: 我怎么给我看类访问的面目的的定义在我的控制器吗?

这里是我的实现,如果它可以帮助:

CustomView.h:

#import "PolygonShape.h"

@interface CustomView : UIView {
    IBOutlet PolygonShape *polygon;
}
- (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;

@end

控制器。h:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h"

@interface Controller : NSObject {
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet PolygonShape *polygon;
    IBOutlet PolygonView *polygonView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
- (void)updateInterface;
@end
有帮助吗?

解决方案

后你找出来,它可能不会伤害碰上一些目标-c基础:

http://www.cocoacast.com/?q=node/103

其他提示

找到我自己的答案,我错过了一个setPolygon方法在我CustomView链接。愚蠢的...

CustomView.h:

#import "PolygonShape.h"

@interface CustomView : UIView {
    IBOutlet PolygonShape *polygon;
}

@property (readwrite, assign) PolygonShape *polygon;

- (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;

@end

在CustomView.m:

@implementation CustomView

@synthesize polygon;

...

@end

控制器。m:

- (void)awakeFromNib { 
    // configure your polygon here 
    polygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
    [polygonView setPolygon:polygon];
    NSLog (@"My polygon:  %@", [polygon description]);
} 

我刚刚完成赋3最后一晚。我解决了这个连接所有接口的建设者。第一,我创造了一个出口上"PolygonView")子类的PolygonShape然后把它连接到的实例,多边形模型。从我读的小组和其他各种网站,我不认为这是一个正确的方式连接这)模型和控制器。但它的工作我觉得没有什么不妥的认知道有关的模型。

那么,为什么你不宣布他们作为特性之类的?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top