2010-06-07 3 views
0

안녕하세요, 저는 목표 -j/c와 카푸치노에 익숙하지 않습니다.Objective-J Cappuccino 버튼을 선택한 상태에서 패널을 새로 고침 할 때 주 메뉴의 버튼 목록을 원합니다.

아래 내가해야 할 일은 http://github.com/jfahrenkrug/CappuccinoLocations1 에서 촬영 된 코드는 다음과 같습니다

난 당신이 MAINVIEW에 LocationButton 클릭 5 개 그래서 버튼이있는 CPView라는 즉 MAINVIEW 인 착륙 메인 메뉴가 필요 MainView가 jfahrenkrug의 작업 내용을 표시하는 LocationView로 대체되었습니다. 비슷한 효과가 서로 다른 버튼에서도 발생합니다.

이 접근 방식을 처리하는 올바른 목표 -c/j 방법은 무엇입니까?

@import <Foundation/CPObject.j> 
@import "src/Location/LocationView.j" 

@implementation AppController : CPObject 
{ 
    LocationView locationView; 
} 

- (void)applicationDidFinishLaunching:(CPNotification)aNotification 
{ 
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()   styleMask:CPBorderlessBridgeWindowMask], 
     mainContentView = [theWindow locationView], 
     bounds = [locationView bounds]; 


[mainContentView setBackgroundColor:[CPColor colorWithRed:212.0 /255.0 green:221.0/ 255.0 blue:230.0/255.0 alpha:1.0]]; 

locationView = [[LocationView alloc] initWithFrame:CGRectMake(0,0,920.0,590.0)]; 
[locationView setCenter:[mainContentView center]]; 
[locationView setBackgroundColor:[CPColor whiteColor]] 
[locationView setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin |  CPViewMinYMargin | CPViewMaxYMargin]; 

var shadow = [[CPShadowView alloc] initWithFrame:CGRectMakeZero()]; 
[shadow setFrameForContentFrame:[locationView frame]]; 
[shadow setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; 
[mainContentView addSubview:shadow]; 
[mainContentView addSubview:locationView]; 

[theWindow orderFront:self]; 

} 

이제 우리는 locationView.j

@import "LocationsController.j" 
@import "LocationListView.j" 
@import "MapController.j" 
@import "LocationsToolbar.j" 
@import "LocationDetailView.j" 
@import "LocationDetailController.j" 

@implementation LocationView : CPView 
{ 
    LocationsController locationsController; 
    LocationListView locationListView; 
    MapController mapController; 
    MKMapView mapView; 
    CPTextField coordinatesLabel; 
    LocationsToolbar locationsToolbar; 
    LocationDetailView locationDetailView; 
    LocationDetailController locationDetailController; 
    CPTextField searchField; 

    // id delegate @accessors; 
} 

- (id)initWithFrame:(CGRect)aFrame 
{ 
    self = [super initWithFrame:aFrame]; 
    if(self){ 

    locationsController = [[LocationsController alloc] init]; 
    [locationsController loadExampleLocations]; 

    locationListView = [[LocationListView alloc] initWithFrame:CGRectMake(0.0,0.0,226.0,400.0)]; 
    [locationListView setContent:[locationsController locations]]; 
    [locationListView setDelegate:locationsController]; 
    [locationsController setLocationListView:locationListView]; 

    var locationScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(10.0,65.0,243.0,400.0)]; 
    [locationScrollView setDocumentView:locationListView]; 
    [locationScrollView setAutohidesScrollers:YES]; 
    [[locationScrollView self] setBackgroundColor:[CPColor whiteColor]]; 
    [self addSubview:locationScrollView]; 

    mapController = [[MapController alloc] init]; 

    mapView = [[MKMapView alloc] initWithFrame:CGRectMake(510,65,400,400) apiKey:''  ]; 
    [mapView setDelegate:self]; 
    mapController.mapView = mapView; 
    [self addSubview:mapView]; 

    coordinatesLabel = [[CPTextField alloc]  initWithFrame:CGRectMake(510,465,200,35)]; 
    [coordinatesLabel setTextColor:[CPColor colorWithHexString:@"009900"]]; 
    [coordinatesLabel setFont:[CPFont systemFontOfSize:14.0]]; 
    [coordinatesLabel setEditable:NO]; 
    [coordinatesLabel setStringValue:@"-/-"]; 
    [mapController setCoordinatesLabel:coordinatesLabel]; 
    [self addSubview:coordinatesLabel]; 

    locationsToolbar = [[LocationsToolbar alloc] initWithFrame:CGRectMake(10.0,467.0,226.0,25.0)]; 
    [locationsToolbar setDelegate:locationsController]; 
    [self addSubview:locationsToolbar]; 

    locationDetailController = [[LocationDetailController alloc] init]; 
    locationDetailController.mapController = mapController; 
    locationsController.locationDetailController = locationDetailController; 
    [mapController setDelegate:locationDetailController]; 

    locationDetailView = [[LocationDetailView alloc] initWithFrame:CGRectMake(510,490,400,90)]; 
    [locationDetailView setDelegate:locationDetailController]; 
    [locationDetailController setLocationDetailView:locationDetailView]; 
    [self addSubview:locationDetailView]; 

    searchField = [CPTextField roundedTextFieldWithStringValue:@"" placeholder:@"Location" width:200.0]; 
    [searchField setFrameOrigin:CGPointMake(510.0,35.0)]; 
    [searchField setDelegate:self]; 
    [self addSubview:searchField]; 

    var searchButton = [[CPButton alloc] initWithFrame:CGRectMake(710.0,37.0,60.0,24.0)]; 
    [searchButton setTitle:"Search"]; 
    [searchButton setTarget:self]; 
    [searchButton setAction:@selector(searchLocation)]; 
    [self addSubview:searchButton]; 

    } 
    return self; 

} 

답변

1

은 내가 당신의 질문을 이해하지만, 기본적으로 윈도우가 기본보기 콘텐츠보기라는이 확실하지 않다 있습니다. 당신은 이렇게 얻는다 :

var contentView = [theWindow contentView]; 

하위보기 (및 단추)를 추가 할 수 있습니다.

[contentView addSubview:myLocationView]; 

하위보기의 위치는 하위보기의 '프레임'에 의해 결정됩니다.

[myLocationView setFrame:CGRectMake(10, 10, 100, 100)]; 

이전보기를 제거하거나 setSubviews 메시지를 사용하여 콘텐츠보기의 하위보기를 다른 것으로 바꿀 수 있습니다.

[contentView setSubviews:[aButton, anotherButton]]; 

그래서 기본적으로 당신은, 서로에 대한 하나 개의보기를 교환하려는 당신이 원하는 새로운 전망의 슈퍼 뷰 'setSubviews'을 호출하는 경우. 희망은 시작하는 데 도움이됩니다.

+0

슬프게도 작동하지 않는 날개가있어, 나는 객관적인 C 책을 갖고이 언어와 API를 공부했습니다. 귀하의 응답이 정말로 도움이되었지만! thnx (http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/ObjC.pdf) – Setori

+0

은 브라우저 비 호환성 문제로 밝혀졌습니다. 사파리에서 잘 작동합니다. – Setori