質問

スタンフォード大学の iPhone開発コースをフォローしていますOpen-University、および assignment3 で2日間ブロックされました。ここで私を助けることができますか?

タスクは次のとおりです。

  1. PolygonShapeオブジェクトを表示するカスタムUIViewサブクラスを作成します
  2. 必要に応じてポリゴンの詳細を取得できるように、PolygonShapeオブジェクトへのビュークラスアクセスを許可します

問題は次のとおりです。コントローラで定義されたポリゴンオブジェクトへのビュークラスのアクセスを許可するにはどうすればよいですか

これが役立つ場合の実装を次に示します。

CustomView.h:

#import "PolygonShape.h"

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

@end

Controller.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
役に立ちましたか?

解決

そして、あなたがそれを理解した後、いくつかのObjective-Cの基本を修正するのに害はないかもしれません:

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

他のヒント

自分の答えを見つけましたが、CustomViewで両方をリンクするsetPolygonメソッドが見つかりませんでした...愚かな...

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

in Controller.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を終えました。 Interface Builderでこの接続をすべて解決しました。最初に、<!> quot; PolygonView <!> quot;にアウトレットを作成しました。 PolygonShapeのUIViewサブクラスで、Polygonモデルのインスタンスに接続します。 Googleグループや他のさまざまなサイトで読んだことから、このUIViewをモデルとコントローラーに接続する正しい方法はないと思います。しかし、うまくいきました。モデルを認識しているビューには何も問題はないと思います。

では、なぜクラスのプロパティとして宣言しないのですか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top