gpt4 book ai didi

objective-c - 使用 NSButton 打开 web URL - Mac OS

转载 作者:太空狗 更新时间:2023-10-30 03:34:16 25 4
gpt4 key购买 nike

我需要一些关于特定复制和粘贴代码的帮助来帮助我运行它。我希望用户点击一个 NSButton,它将启动 safari 或他们的默认网络浏览器。

我在表单上添加了一个 NSButton,然后为其添加了声明和实现,但仍然无法正常工作。为什么它不起作用?提前致谢...

 --------.h file--------
// Copyright (c) 2013 Company. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "HttpRequest.h"
#import "JSON.h"
#import "ChimpKit.h"
#define IS_REGISTERED @"IS_REGISTERED"
#define NORMAL_0 0
#define MAILCHIMP_1 1

@protocol RegistrationWindowDelegate

-(void) registrationDidFinished;

@end

@interface RegistrationWindowController : NSWindowController<HttpRequestDelegate,ChimpKitDelegate,NSWindowDelegate> {


IBOutlet NSButton *pushApp1; //Newly added NSButton for opening Web URL

IBOutlet NSWindow *registerWindow;
IBOutlet NSWindow *privacyWindow;
IBOutlet NSTextField *firstNameField, *lastNameField, *emailField, *verfilyEmailField;
IBOutlet NSPopUpButton *countryPopUpBtn;
IBOutlet NSButton *updateCheckBox, *promotionCheckBox;
IBOutlet NSMenuItem *registerMenuItem;
IBOutlet NSProgressIndicator *progressIndicator;
IBOutlet NSButton *registerSoftware,*registerLater;
id<RegistrationWindowDelegate> delegate;

}
@property(nonatomic,assign) id<RegistrationWindowDelegate> delegate;
- (id)initForRegistrationServer:(int) registrationServer withDelegate:(id<RegistrationWindowDelegate>) delegate;
+ (BOOL) isRegistered;
- (void) setRegistered:(BOOL)state;
- (void) openWindow:(id) sender;
- (BOOL)isValidEmail:(NSString *)email;
-(void) registerWithNormal;
- (void) registerWithMailChimpForApps;
- (NSArray *)addCountries;

@end

这是我的 .m 文件(我尝试使用在网上找到的代码片段)

--------.m file--------

// Copyright (c) 2013 Computer. All rights reserved.
//

#import "RegistrationWindowController.h"

@interface RegistrationWindowController ()

@end

int registrationServer;

@implementation RegistrationWindowController
@synthesize delegate;

- (IBAction)pushApp1:(id)sender {

///Found this snippet on the web, but doesnt work
NSURL *myURL = [NSURL URLWithString:@"http://www.google.com"];
[[NSWorkspace sharedWorkspace] openURL:myURL];


///// Also Found this snippet on the web, but doesnt work
// NSString *s = [ NSString stringWithFormat:@"http://www.google.com"];
// [[NSApplication sharedApplication] openURL:[NSURL URLWithString:s]];



}

最佳答案

这应该有效:

-(IBAction)pushApp1:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://stackoverflow.com"]];
}

关于objective-c - 使用 NSButton 打开 web URL - Mac OS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17497561/

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