English 中文(简体)
将UIToolbar置于Xcode 4.3的关键板上。
原标题:placing a UIToolbar over the Keyboard in Xcode 4.3

这是我的第一个职位,我对斯里的方案拟订工作来说是相当新的。 我正在使用Xcode 4.3,并可能是一个容易的问题。 我全心全意想把工具棒放在顶板上,该板上有一个前线。 我发现,在Xcode正在使用接口建筑商时,如何做到这一点。 但是,我找不到最新版本的x编码。 因此,我已经从互联网和果树丛网站上找到了这些东西,并提出了一些法典。 唯一一点是,它不工作! 我发现的错误是,根据投入AcessoryView的行文将不动产转让给读物。 我知道,这或许是简单的,但在将法典从前版本移至新版本时,我很可能夸大一些。 一些人可以检查我的法典,让我知道我错了什么。 非常感谢。 我的档案包括我的档案。

    #import <UIKit/UIKit.h>

    @interface keyboardViewController : UIViewController


    @property (retain, nonatomic) IBOutlet UIView *textField1;
    @property (retain, nonatomic) IBOutlet UIView *textField2;

    @property (nonatomic, retain) UIToolbar *keyboardToolbar;

    -(void)resignKeyboard:(id)sender;
    -(void)previousField:(id)sender;
    -(void)nextField:(id)sender;

    @end

损耗

    #import "keyboardViewController.h"

    @interface keyboardViewController ()

    @end

    @implementation keyboardViewController
    @synthesize textField1;
    @synthesize textField2;
    @synthesize keyboardToolbar;

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        if (keyboardToolbar == nil)
        {
            keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,                            self.view.bounds.size.width, 44)]; 

            UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithTitle:@"previous" 
                                                                               style:UIBarButtonItemStyleBordered
                                                                      target:self 
                                                                      action:@selector(previousField:)];
            UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"next" 
                                                                           style:UIBarButtonItemStyleBordered
                                                                          target:self 
                                                                          action:@selector(nextField:)];

            UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:nil action:nil];


            UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemDone) target:self action:@selector(resignKeyboard:)];



            [keyboardToolbar setItems:[[NSArray alloc] initWithObjects:previousButton, nextButton, extraSpace, done, nil]];

            textField1.inputAccessoryView  = keyboardToolbar;
            textField2.inputAccessoryView  = keyboardToolbar;


        }


    }

    -(void) resignKeyboard:(id)sender
    {
        if ([textField1 isFirstResponder])
            [textField1 resignFirstResponder];

        else if ([textField2 isFirstResponder])
        [textField2 resignFirstResponder];
    }

    -(void) previousField:(id)sender
    {
        if ([textField1 isFirstResponder])
            [textField2 becomeFirstResponder];

        else if ([textField2 isFirstResponder])
            [textField1 becomeFirstResponder];
    }


    -(void) nextField:(id)sender
    {
        if ([textField1 isFirstResponder])
            [textField2 becomeFirstResponder];

        else if ([textField2 isFirstResponder])
            [textField1 becomeFirstResponder];
    }


    - (void)viewDidUnload
    {
        [self setTextField1:nil];
        [self setTextField2:nil];
        [self setKeyboardToolbar:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    @end
最佳回答
@interface keyboardViewController : UIViewController<UITextFieldDelegate>


@property (retain, nonatomic) IBOutlet UITextField *textField1;
@property (retain, nonatomic) IBOutlet UITextField *textField2;

页: 1

        textField1.inputAccessoryView  = keyboardToolbar;
        textField2.inputAccessoryView  = keyboardToolbar;

遵循这些守则

for (id view in self.view.subviews) {
    if ([view isKindOfClass:[UITextField class]]) {
        [(UITextField *)view setInputAccessoryView:keyboardToolbar];
    }
}

继承该法典

-(void) resignKeyboard:(id)sender{

         [self.view endEditing:YES];
}

而不是

-(void) resignKeyboard:(id)sender
    {
        if ([textField1 isFirstResponder])
            [textField1 resignFirstResponder];

        else if ([textField2 isFirstResponder])
        [textField2 resignFirstResponder];
    }

添加这一法典 D. 离婚法

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

以及

-(void)nextField:(id)sender{

    if ([textField1 isFirstResponder]) {

        [textField2 becomeFirstResponder];
        [previousButton setEnabled:YES];
        [nextButton setEnabled:NO];
    }
}

-(void)previousField:(id)sender{

    if ([textField2 isFirstResponder]) {

        [textField1 becomeFirstResponder];
        [nextButton setEnabled:YES];
        [previousButton setEnabled:NO];
    }
}

-(void)keyboardWillShow:(id)sender{

    if ([textField2 isFirstResponder]) {

        [nextButton setEnabled:NO];
        [previousButton setEnabled:YES];
    }else if ([textField1 isFirstResponder]) {

        [nextButton setEnabled:YES];
        [previousButton setEnabled:NO];
    }
}
问题回答

当你打算增加一个“单 but子”时,如果你的文本类型是“国际钻石公司” 类型 aca default default done done 为此,你必须补充以下内容:

    UIToolbar *boolbar = [UIToolbar new];
    boolbar.barStyle = UIBarStyleBlackTranslucent;
    [boolbar sizeToFit];


    UIBarButtonItem *leftBarButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBtnClicked)];

    NSArray *array = [NSArray arrayWithObjects:cancelleftBarButton, nil];
    [leftBarButton release];
    [boolbar setItems:array];

    textField_phnNumber.inputAccessoryView = boolbar;

/ 甄选者采用的方法

- (避免)doneBtnClicked 页: 1

[textField_phnNumber resignFirstResponder];

}

<>0> 如果你使用UIText Field的话,在案文中添加了这一句:SidBeginEditing 代表方法。

该法典将UIToolbar的“Done”纽芬兰文登在right上,高于键盘:

UIToolbar *tbAboveKeyboard = [[UIToolbar alloc] init];
tbAboveKeyboard.barStyle = UIBarStyleBlackTranslucent;
[tbAboveKeyboard sizeToFit];

UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *rightBarButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonClicked:)];

NSArray *array = [NSArray arrayWithObjects:flexibleSpaceLeft, rightBarButton, nil];
[rightBarButton release];
[tbAboveKeyboard setItems:array];

yourTextView.inputAccessoryView = tbAboveKeyboard;
[tbAboveKeyboard release];  

...

- (void)doneButtonClicked:(id)sender
{
    [searchTextField resignFirstResponder];
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签