Я новичок в iOS, и я следую this tutorial.Невозможно подключить IBAction для просмотра
Вот скриншот от меня, пытающегося подключить IBAction к моему представлению.
Я хочу выполнить метод releaseKeyboard
всякий раз, когда я касаюсь вида (т. Е. Закрываю клавиатуру).
Я не использую раскадровку.
Мои файлы:
- challAppDelegate.h
- challAppDelegate.m
- challViewController.h
- challViewController.m
- challViewController.xib
challAppDelegate.h
#import <UIKit/UIKit.h>
@interface challAppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *navigationController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
challAppDelegate.m
#import "challAppDelegate.h"
#import "challViewController.h"
@implementation challAppDelegate
@synthesize window = _window;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *rootController =
[[challViewController alloc]
initWithNibName:@"challViewController" bundle:nil];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
...
...
challViewController.h
#import <UIKit/UIKit.h>
@interface challViewController : UIViewController
@property(nonatomic, retain) IBOutlet UITextField *signInEmailAddress;
@property(nonatomic, retain) IBOutlet UITextField *signInPassword;
@property(nonatomic, retain) IBOutlet UIButton *signInSignInButton;
@property(nonatomic, retain) IBOutlet UIButton *signInRegisterButton;
-(void) releaseKeyboardAction;
-(IBAction) signInAction:(int)sender;
-(IBAction) registerAction:(int)sender;
-(IBAction) releaseKeyboard:(id)sender;
@end
challViewController.m
#import "challViewController.h"
@interface challViewController()
@end
@implementation challViewController
@synthesize signInEmailAddress; // cria os getters e setters
@synthesize signInPassword; // cria os getters e setters
@synthesize signInSignInButton; // cria os getters e setters
@synthesize signInRegisterButton; // cria os getters e setters
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Sign In";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)releaseKeyboardAction
{
[signInEmailAddress resignFirstResponder];
[signInPassword resignFirstResponder];
}
- (IBAction)releaseKeyboard:(id)sender
{
[self releaseKeyboardAction];
}
- (IBAction)registerAction:(int)sender
{
//
}
- (IBAction)signInAction:(int)sender
{
//
}
@end
Что я делаю неправильно?
Благодаря
Вы не можете подключить 'IBAction' как' IBOutlet' для вашего вида. Что вы хотите сделать с представлением и методом 'releaseKeyboard:'? – Rich
Чтобы отпустить клавиатуру, когда вы нажимаете в любом месте просмотра (поскольку на клавиатуре нет кнопки выхода). Я подключил IBActions к текстовым полям и кнопкам. –
Есть кнопка «Готово» - когда вы нажимаете эту кнопку на клавиатуре, вы хотите, чтобы клавиатура исчезла? – Rich