У меня есть очень простое веб-приложение Objective-J, которое представляет собой ярлык и кнопку. Текст метки изменяется при нажатии кнопки. Я также хочу изменить название кнопки. Если я добавлю оператор изменения в функцию подкачки ниже (функция, которая запускается при нажатии кнопки), то веб-приложение не запускается должным образом.
Как я могу изменить этот код так, чтобы кнопка гласила: «Приходит Томми», когда текст метки «Прощай, Томми»?
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPTextField label;
CPButton button;
}
// Launches UI in the App
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],contentView = [theWindow contentView];
label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:@"Hello Tommy Jones!"];
[label setFont:[CPFont boldSystemFontOfSize:24.0]];
[label sizeToFit];
[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[label setCenter:[contentView center]];
[contentView addSubview:label];
[label setAlignment:CPCenterTextAlignment];
button = [[CPButton alloc] initWithFrame: CGRectMake( CGRectGetWidth([contentView bounds])/2.0 - 50, CGRectGetMaxY([label frame]) + 10, 100, 24 )];
[button setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[button setTitle:"Tommy Leaves"];
[button setTarget:self];
[button setAction:@selector(swap:)];
[contentView addSubview:button];
[theWindow orderFront:self];
// Uncomment the following line to turn on the standard menu bar.
[CPMenu setMenuBarVisible:YES];
}
// Executes when button is pressed
- (void)swap:(id)sender
{
if
([label stringValue] == "Hello Tommy Jones!") [label setStringValue:"Good Bye Tommy!"];
// [button setTitle:"Tommy Leaves"];
// [contentView addSubview:button];
else
[label setStringValue:"Hello Tommy Jones!"];
// [button setTitle:"Tommy Arrives"];
}
@end