【问题标题】:How actions to Next/Previous Keyboard ToolbarCustom iOS7如何操作到下一个/上一个键盘工具栏自定义 iOS7
【发布时间】:2014-07-10 07:55:24
【问题描述】:

我正在尝试在键盘工具栏上设置下一个/上一个按钮,我想进入导航以进入下一个/上一个文本字段。这是我正在尝试的。

如何使用系统栏按钮项更改为文本字段?

-(void)addTeam{
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(15, (0+(50*[teamsArray count])), 273, 50)];
        [view setTag:[teamsArray count]+1];

        UILabel *lblTeamName = [[UILabel alloc ] initWithFrame:CGRectMake(5,0,58,20)];
        [lblTeamName setBackgroundColor:[UIColor clearColor]];
        lblTeamName.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(12.0)];
        lblTeamName.text = [NSString stringWithFormat:@"Team %i",[teamsArray count]+1];
        [lblTeamName setTag:7];
        [view addSubview:lblTeamName];

        UITextField* txtTeamName = [[UITextField alloc]initWithFrame:CGRectMake(5,20,150,30)];
        [txtTeamName setBorderStyle:UITextBorderStyleRoundedRect];
        [txtTeamName setPlaceholder:@"Team Name"];
        [txtTeamName addTarget:self action:@selector(hideKeyboard) forControlEvents:UIControlEventEditingDidEndOnExit];
        [txtTeamName setDelegate:self];
        [view addSubview:txtTeamName];

        UIButton *btnDelete = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btnDelete addTarget:self
                      action:@selector(btnDelete_OnTouch:)
         forControlEvents:UIControlEventTouchDown];
        [btnDelete setTag:[teamsArray count]];
        [btnDelete setTitle:@"-" forState:UIControlStateNormal];
        btnDelete.frame = CGRectMake(160, 20, 20, 30);
        [view addSubview:btnDelete];

        [scrollView addSubview:view];
        [teamsArray addObject:view];

    }

    -(BOOL)textFieldShouldBeginEditing: (UITextField *)textField

    {
        UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];

        keyboardToolBar.barStyle = UIBarStyleDefault;
        [keyboardToolBar setItems: [NSArray arrayWithObjects:
                                    [[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],

                                    [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
                                    [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                    [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
                                    nil]];
        textField.inputAccessoryView = keyboardToolBar;

    }



    - (void)nextTextField {

        ????


    }

    -(void)previousTextField
    {

        ????

    }

【问题讨论】:

标签: objective-c button ios7 keyboard


【解决方案1】:

您可以使用下一个和上一个按钮, How to navigate through textfields (Next / Done Buttons)

并在 ViewDidLoad 中执行此操作

    UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];

    keyboardToolBar.barStyle = UIBarStyleDefault;
    [keyboardToolBar setItems: [NSArray arrayWithObjects:
                                [[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],

                                [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
                                [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
                                nil]];
    textField.inputAccessoryView = keyboardToolBar;

【讨论】:

    猜你喜欢
    • 2013-09-28
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    相关资源
    最近更新 更多