首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何对下一个/上一个键盘执行操作ToolbarCustom iOS7

如何对下一个/上一个键盘执行操作ToolbarCustom iOS7
EN

Stack Overflow用户
提问于 2014-05-21 23:08:33
回答 1查看 805关注 0票数 0

我正在尝试设置键盘工具栏上的“下一步”/“上一步”按钮,我想将其放入导航以转到“下一步/上一步”文本字段。这就是我正在尝试的。

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

代码语言:javascript
复制
-(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
    {

        ????

    }
EN

回答 1

Stack Overflow用户

发布于 2014-05-22 11:03:52

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

并在ViewDidLoad中执行此操作

代码语言:javascript
复制
    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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23787160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档