문제

나는 따르고있다 iPhone Dev 코스 Stanford Open-University에서 2 일 동안 차단되었습니다. 과제 3, 누군가 여기서 나를 도울 수 있을까요?

작업은 다음과 같습니다.

  1. 다각형 셰이프 개체를 표시 할 사용자 정의 UIView 서브 클래스 만들기
  2. 필요에 따라 다각형의 세부 사항을 검색 할 수 있도록 다각형 셔프 객체에 대한 조회 클래스 액세스 권한을 부여하십시오.

문제는: 컨트롤러에 정의 된 다각형 객체에 대한 내보기 클래스에 액세스하는 방법은 무엇입니까?

도움이 될 수있는 경우 내 구현은 다음과 같습니다.

CustomView.h :

#import "PolygonShape.h"

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

@end

컨트롤러 : :

#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

다른 팁

내 자신의 대답을 찾았다. 나는 내 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

안에 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을 마쳤습니다. 인터페이스 빌더 에서이 연결을 모두 해결했습니다. 먼저 Polygonshape의 "Polygonview"Uiview 서브 클래스에 출구를 만들어 다각형 모델의 인스턴스에 연결했습니다. Google 그룹과 다른 다양한 사이트에서 읽은 내용 에서이 UIView를 모델 및 컨트롤러에 연결하는 올바른 방법이 없다고 생각합니다. 그러나 그것은 모델에 대한 견해에 아무런 문제가 없다고 생각했습니다.

그렇다면 왜 수업의 속성으로 선언하지 않습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top