gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:38:22 24 4
gpt4 key购买 nike

亲爱的所有人,我对Objective-J/C和 Cappuccino 并不陌生,我不确定这一切如何融合在一起。

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

我需要一个登陆主菜单,它是一个名为CPView的CPView,即MainView,具有五个左右按钮,当您单击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;

}

最佳答案

我不确定我是否理解您的问题,但实际上一个窗口有一个默认 View ,称为内容 View 。您可以这样获得:

var contentView = [theWindow contentView];

您可以向内容 View 添加 subview (和按钮)。
[contentView addSubview:myLocationView];

这些 subview 的位置由 subview 的“框架”确定。
[myLocationView setFrame:CGRectMake(10, 10, 100, 100)];

您可以通过删除先前的 View 或使用setSubviews消息将内容视​​图的 subview 替换为其他 View 。
[contentView setSubviews:[aButton, anotherButton]];

因此,从本质上讲,如果您想将一个 View 换成另一个 View ,请在其 super View 上使用所需的新 View 调用“setSubviews”。希望能帮助您入门。

关于cappuccino - Objective-J Cappuccino想要主菜单上的按钮列表,当我单击面板刷新并选择按钮的UI时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2988214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com