0

親愛なる皆さん、私はobjective-j / cとカプチーノに不慣れですが、これがどのように組み合わされているのかよくわかりません。

以下のコードはhttp://github.com/jfahrenkrug/CappuccinoLocations1から取得した ものです。私がする必要があるのは次のとおりです。

ランディングメインメニューが必要です。つまり、5つほどのボタンがあるMainViewと呼ばれるCPViewです。MainViewのLocationButtonをクリックすると、MainViewがLocationViewに置き換えられ、jfahrenkrugの作業の内容が表示されます。同様の効果は、他のボタンでも発生します。

このアプローチを処理する正しいObjective-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;

}
4

1 に答える 1

1

あなたの質問を理解できるかどうかはわかりませんが、基本的にウィンドウにはコンテンツビューと呼ばれるデフォルトのビューがあります。あなたはそのようにそれを得る:

var contentView = [theWindow contentView];

コンテンツビューにサブビュー(およびボタン)を追加できます。

[contentView addSubview:myLocationView];

これらのサブビューの場所は、サブビューの「フレーム」によって決定されます。

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

以前のビューを削除するか、setSubviewsメッセージを使用して、コンテンツビューのサブビューを別のものに置き換えることができます。

[contentView setSubviews:[aButton, anotherButton]];

したがって、基本的に、あるビューを別のビューに交換する場合は、必要な新しいビューを使用して、そのスーパービューで「setSubviews」を呼び出します。それがあなたが始めるのに役立つことを願っています。

于 2010-06-08T02:36:00.533 に答える