简体   繁体   中英

How to get text from search field?

I'm making a basic web browser to start me off and I would like to add some new features. However, I can't get the text from the urlbar (which is just a searchbar) stored in a variable. Could someone please help?

Here's my zseAppDelegate.h file:

#import <Cocoa/Cocoa.h>

@interface zseAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSSearchField* searchfield;
@end

Here's my zseAppDelegate.m file:

#import "zseAppDelegate.h"

@implementation zseAppDelegate
@synthesize searchfield,window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSString * searchf = [searchfield, stringValue]
};

@end

NSSearchField inherits from NSTextField , which is an NSControl . That implements stringValue .

So, eg

NSString *searchFieldValue = [searchField stringValue];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM