Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:19:47+00:00 2026-06-09T21:19:47+00:00

I’m having a problem with a Segmented Control in a Toolbar on my Keyboard

  • 0

I’m having a problem with a Segmented Control in a Toolbar on my Keyboard in my current iOS App. I’m trying to basically have a keyboard with a Toolbar that has a Segment control on the left hand side with Previous/Next options and then a Done button. I got it all setup and everything is firing correctly except for the one thing I want to do is make sure that the correct segment is pre-selected when the appropriate text box is selected. The problem I’ve been running into is that no matter what text field I click on, the wrong segment is selected and I have to push it twice to get it in the right order.

Here is the code of the toolbar being created (this is in ViewDidLoad)

keyBar = [[UIToolbar alloc] init];
[keyBar setBarStyle:UIBarStyleBlack];
[keyBar sizeToFit];

segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Previous", @"Next", nil]];
[segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
segControl.selectedSegmentIndex = 0;
[segControl addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventValueChanged];

UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segControl];
UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];

NSArray *itemArray = [NSArray arrayWithObjects:segButton, flexButton, doneButton, nil];
[segButton release];
[flexButton release];
[doneButton release];

[keyBar setItems:itemArray];

And here is how I add the bar to both text fields in my table (using a custom cell as well)

 #pragma mark - User Name Row
if (section == 0 && row == 0) {
    static NSString *TextEntryCell = @"TextCell";
    TextCell *customCell = (TextCell *)[tableView dequeueReusableCellWithIdentifier:TextEntryCell];
    if (customCell == nil) {
        NSString *nibName = nil;
        if (iPad) {
            nibName = @"TextCell_iPad";
        }
        else {
            nibName = @"TextCell";
        }
        NSArray *outlets = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
        for (id currentObject in outlets) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                customCell = (TextCell *)currentObject;
                break;
            }
        }
    }

    customCell.selectionStyle = UITableViewCellSelectionStyleNone;
    customCell.typeLbl.text = @"User Name:";
    customCell.textField.placeholder = @"Enter User Name";
    customCell.textField.returnKeyType = UIReturnKeyNext;
    customCell.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    customCell.textField.tag = 1;
    //segControl.selectedSegmentIndex = 0;
    [customCell.textField setInputAccessoryView:keyBar];


    return customCell;
}

#pragma mark - Password Row
if (section == 0 && row == 1) {
    static NSString *TextEntryCell = @"TextCell";
    TextCell *customCell = (TextCell *)[tableView dequeueReusableCellWithIdentifier:TextEntryCell];
    if (customCell == nil) {
        NSString *nibName = nil;
        if (iPad) {
            nibName = @"TextCell_iPad";
        }
        else {
            nibName = @"TextCell";
        }
        NSArray *outlets = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
        for (id currentObject in outlets) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                customCell = (TextCell *)currentObject;
                break;
            }
        }
    }

    customCell.selectionStyle = UITableViewCellSelectionStyleNone;
    customCell.typeLbl.text = @"Passphrase:";
    customCell.textField.placeholder = @"Enter Passphrase";
    customCell.textField.returnKeyType = UIReturnKeyGo;
    customCell.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    customCell.textField.tag = 2;
    segControl.selectedSegmentIndex = 1;
    [customCell.textField setInputAccessoryView:keyBar];


    return customCell;
}

So as you can see I basically want it setup so that when the first Text box is selected then the Previous segment in the segment control is already selected and then the the same for the second text box and the next segment. But no matter what I’ve tried so far when I click on either text box the second segment is always the default selected item so in the first Textfield it’s a bit clunky since I have to click both indexes then it starts to work right. After I do that then it works perfectly, but it’s just that initial display that is giving me an issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:19:49+00:00Added an answer on June 9, 2026 at 9:19 pm

    You cannot add the bar to both views – its one object and you cannot share it. You should create two such bars, add a unique one to both views. Keep a reference to both segmented controls, and update both to reflect the selected text box. I believe that architecture will solve this. If not, after you do it, update the question or add a comment to this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.