Objective-J Cappuccino 想要主菜单上的按钮列表,当我单击面板时,会刷新并选择按钮的 UI

发布于 2024-09-04 11:29:22 字数 5016 浏览 7 评论 0原文

亲爱的大家,我是 Objective-j/c 和卡布奇诺的新手,不太确定这一切是如何结合在一起的。

下面的代码取自 http://github.com/jfahrenkrug/CappuccinoLocations1 我需要做的是:

我需要一个登陆主菜单,它是一个名为 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;

}

Dear all, I am new to objective-j/c and cappuccino not really sure how this all fits together.

The code below is taken from http://github.com/jfahrenkrug/CappuccinoLocations1
What I need to do is:

I need a landing main menu which is a CPView called ie MainView with five or so buttons, when you click on the LocationButton on MainView is replaces MainView by with LocationView, which displays the contents of jfahrenkrug's work. A similar effect will happen with each other button.

What is the correct Objective-c/j way of handling this approach?

@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];

}

Now we have the 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;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虐人心 2024-09-11 11:29:22

我不确定我是否理解您的问题,但本质上窗口有一个称为内容视图的默认视图。您可以像这样获得它:

var contentView = [theWindow contentView];

您可以在内容视图中添加子视图(和按钮)。

[contentView addSubview:myLocationView];

这些子视图的位置由子视图的“框架”确定。

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

您可以通过删除以前的视图或使用 setSubviews 消息将内容视​​图的子视图替换为其他内容。

[contentView setSubviews:[aButton, anotherButton]];

因此,本质上,如果您想将一个视图替换为另一个视图,请在其超级视图上使用您想要的新视图调用“setSubviews”。希望这有助于您入门。

I'm not sure I understand your question but essentially a window has a default view called the content view. You get it like so:

var contentView = [theWindow contentView];

To the content view you can add subviews (and buttons).

[contentView addSubview:myLocationView];

The location of those subviews is determined by the 'frame' of the subview.

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

You can replace the content view's subviews with something else by either removing the previous views or using the setSubviews message.

[contentView setSubviews:[aButton, anotherButton]];

So essentially if you want to swap out one view for another, call 'setSubviews' on its super view with the new views you want. Hope that helps to get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文