2014-07-06 40 views
0

Xcode 5/iOS 7.无法在当前项目中隐藏iOS键盘(xcode 5)

此问题一直让我疯狂,因为现在的一天中有更好的一部分。在我目前的项目中,我无法使用resignFirstResponder隐藏iOS键盘。然而,奇怪的是,我能够在我目前正在进行的所有其他项目中工作。下面的代码。非常感谢,伙计们!

ViewController.h:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UITextFieldDelegate> 
{  
    IBOutlet UISegmentedControl *selectcontrolNumbers; 
    IBOutlet UILabel *output; 
    int grossNetVar; 
    double calcVariable; 
    IBOutlet UIButton *hideConvertNet; 
    IBOutlet UIButton *hideConvertGross; 

} 

@property (strong, nonatomic) IBOutlet UITextField *dollarTextField; 
@property (nonatomic)int grossNetVar; 
@property (nonatomic) double calcVariable; 
- (IBAction)selectAction:(id)sender; 
- (IBAction)convertToNet:(id)sender; 
- (IBAction)convertToGross:(id)sender; 
@end 

ViewController.m:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize grossNetVar; 
@synthesize calcVariable; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.dollarTextField.delegate = self; 
} 

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self.dollarTextField resignFirstResponder]; 
} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


- (IBAction)selectAction:(id)sender { 

    if (selectcontrolNumbers.selectedSegmentIndex == 0){ 
     grossNetVar = 1; 
    } else { 
     grossNetVar = 2; 
    } 

    if (grossNetVar == 1) { 
     hideConvertGross.enabled = YES; 
     hideConvertNet.enabled = NO; 
    } else { 
     hideConvertGross.enabled = NO; 
     hideConvertNet.enabled = YES; 
    } 
} 

- (IBAction)convertToNet:(id)sender { 
    NSString *textFieldText = _dollarTextField.text; 
    calcVariable = .85; 
    double dollarTotal = [textFieldText doubleValue]; 
    double netCalc = calcVariable * dollarTotal; 

    NSString *netString = [[NSString alloc]initWithFormat:@"The NET total is %g", netCalc]; 
    output.text = netString; 

} 

- (IBAction)convertToGross:(id)sender { 
} 

@end 
+1

创建一个IBAction为是' - (空)的touchesBegan:(NSSet中*)倒是withEvent:方法(*的UIEvent)event'被称为? – nhgrif

+0

是的 - 右下方viewDidLoad – MrShickadance9

+0

正如@nhgrif指出的那样,在那里放置一个断点,看看它是否被调用。 – mostruash

回答

0

我会建议使用一个工具栏(你可以拖动一个到屏幕到故事板),其只有在键盘打开时才会出现,并在其上放置完成按钮。该按钮的触地得分,你可以做

[donebutton resignFirstResponder];