2013-05-11 3 views
0

액세서리에서 키를 누를 때 텍스트를 UITextField에 입력하는 키보드 액세서리를 구현하는 데 어려움이 있습니다. 상의 사용자가 클릭 '사용자가 아무튼 그래서 @gmail 버튼이 UITextField에 @ gmail.com 현재 이메일 주소를 입력 할'때UITextField에 텍스트 입력이있는 사용자 정의 키보드

Keyboard Accessory Picture

가 궁극적으로 내가 원하는 :이 초안의 모습이었다된다 그것을 타이핑해야합니다. 프로그래밍 방식으로 keyboardaccessoryview를 작성하고 있기 때문에 문제가 발생했습니다. keyboardaccess에서 keyinput을 이메일 주소의 UITextField로 이동시켜야합니다.

NSString *appendThisText = @"@gmail.com"; 
self.textFieldOne.text=[NSString stringWithFormat:@"%@%@", self.textFieldOne.text, appendThisText]; 

으로 IBAction을 시도했지만 작동하지 않았습니다. 제발 도와주세요. 여기에 signInViewController.h

#import <UIKit/UIKit.h> 
#import <AVFoundation/AVAudioPlayer.h> 
#import <AudioToolbox/AudioToolbox.h> 

@interface signInViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate> { 
    AVAudioPlayer *sound; 
    UIButton *myButton; 
    UITextField *textFieldOne; 
    UIButton *gmailButton; 
    UIButton *meButton; 
    UIButton *yahooButton; 
    UIButton *outlookButton; 
    UIView *inputAccView; 
    UIButton *aolButton; 
} 


- (IBAction)playSwoosh:(id)sender; 

- (IBAction)dismiss:(id)sender; 

- (IBAction)toggleUIButtonImage:(id)sender; 

- (IBAction)backgroundTouched:(id)sender; 



@property (weak, nonatomic) IBOutlet UITextField *textFieldOne; 
@property (weak, nonatomic) IBOutlet UITextField *textFieldTwo; 
@property (nonatomic, retain) UIButton *gmailButton; 
@property (nonatomic, retain) UIButton *meButton; 
@property (nonatomic, retain) UIButton *yahooButton; 
@property (nonatomic, retain) UIButton *outlookButton; 
@property (nonatomic, retain) UIButton *aolButton; 
@property (retain, nonatomic) UIButton *myButton; 
@property (nonatomic, retain) UIView *inputAccView; 

@end 

내 코드는 여기에 누군가가 나이 하나 옳은 길을 도와 주시겠습니까 내 signInViewController.m

#import "signInViewController.h" 
#import <QuartzCore/QuartzCore.h> 

@interface signInViewController() 

@end 

@implementation signInViewController 

@synthesize myButton = _myButton; 
@synthesize textFieldOne = _textFieldOne; 
@synthesize textFieldTwo = _textFieldTwo; 
@synthesize inputAccView; 
@synthesize gmailButton; 
@synthesize yahooButton; 
@synthesize meButton; 
@synthesize outlookButton; 
@synthesize aolButton; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
} 
return self; 
} 


- (void)createInputAccessoryView { 
inputAccView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 30.0)]; 
[inputAccView setBackgroundColor:[UIColor clearColor]]; 
[inputAccView setAlpha: 0.8]; 

gmailButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 
[gmailButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal]; 
//[gmailButton sizeToFit] 
[gmailButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
gmailButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12]; 
[gmailButton setFrame: CGRectMake(0.0, 0.0, 60.0, 30.0)]; 
[gmailButton setTitle:@"@Gmail" forState:UIControlStateNormal]; 
[gmailButton setBackgroundColor:[UIColor lightGrayColor]]; 
[inputAccView addSubview:gmailButton]; 

meButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 
[meButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal]; 
//[gmailButton sizeToFit] 
[meButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
meButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12]; 
[meButton setFrame: CGRectMake(60.0, 0.0, 50.0, 30.0)]; 
[meButton setTitle:@"@Me" forState:UIControlStateNormal]; 
[meButton setBackgroundColor:[UIColor lightGrayColor]]; 
[inputAccView addSubview:meButton]; 

yahooButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 
[yahooButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal]; 
//[gmailButton sizeToFit] 
[yahooButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
yahooButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12]; 
[yahooButton setFrame: CGRectMake(110.0, 0.0, 70.0, 30.0)]; 
[yahooButton setTitle:@"@Yahoo" forState:UIControlStateNormal]; 
[yahooButton setBackgroundColor:[UIColor lightGrayColor]]; 
[inputAccView addSubview:yahooButton]; 

outlookButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 
[outlookButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal]; 
//[gmailButton sizeToFit] 
[outlookButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
outlookButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12]; 
[outlookButton setFrame: CGRectMake(180.0, 0.0, 70.0, 30.0)]; 
[outlookButton setTitle:@"@Outlook" forState:UIControlStateNormal]; 
[outlookButton setBackgroundColor:[UIColor lightGrayColor]]; 
[inputAccView addSubview:outlookButton]; 

aolButton = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 
[aolButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal]; 
//[gmailButton sizeToFit] 
[aolButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
aolButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12]; 
[aolButton setFrame: CGRectMake(250.0, 0.0, 50.0, 30.0)]; 
[aolButton setTitle:@"@Aol" forState:UIControlStateNormal]; 
[aolButton setBackgroundColor:[UIColor lightGrayColor]]; 
[inputAccView addSubview:aolButton]; 

} 


- (IBAction)backgroundTouched:(id)sender { 
[_textFieldOne resignFirstResponder]; 
[_textFieldTwo resignFirstResponder]; 
} 


- (void)textFieldDidBeginEditing:(UITextField *)textField { 

if (textField == self.textFieldOne) { 
    [self createInputAccessoryView]; 
    [textField setInputAccessoryView:inputAccView]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 95), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} else if (textField == self.textFieldTwo) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 95), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField { 
if (textField == self.textFieldOne) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 95), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} else if (textField == self.textFieldTwo) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 95), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 
} 


- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
if (textField) { 
    [textField resignFirstResponder]; 
} 
return NO; 
} 

입니다. 내가 출구로 gmailButton에서 textFieldOne로 IBAction 것이라고 가정하지만 프로그래밍 방식으로 구현하는 방법을 잘 모르겠습니다. 그것은 저에게 몇몇 문제점을주고 있습니다. 이 UITextView 변환하는 데 문제가 있지만 UITextInput 프로토콜 또는 무엇을 사용해야 할 지 모르겠다.

답변

2

기본적으로 버튼에 타겟 액션 (예 : IBAction)을 추가하기 만하면됩니다.

- (void)yourButtonTapped 
{ 
    self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"whatever"]; 
} 
+0

그게 전부가 환상적인 : 같은 탭을 처리 할

[yourButton addTarget:self action:@selector(yourButtonTapped) forControlEvents:UIControlEventTouchUpInside]; 

을 그리고 방법을 만듭니다

그냥 버튼이 추가! 나는 그것을 간과했다고 믿을 수 없다. 나는 완전히 그걸 놓친 모든 사건을 다루는 IBAction에 너무 집중했다. 그냥 똑똑 하네. 고맙습니다! – soulshined

+0

나는 당신을 투표 할 것이다. 그러나 나는 충분한 평판이 없다. – soulshined

+0

당신을 환영한다 :-) – d4Rk

관련 문제