Creating a custom toolbar over the iPad keyboard in Xcode

Discussion in 'iOS Programming' started by dpatel, May 25, 2013.

  1. dpatel, May 25, 2013
    Last edited: May 25, 2013

    dpatel macrumors newbie

    Joined:
    May 25, 2013
    #1
    I am using xcode 4.6.2, and i am having trouble making a custom toolbar on top of the ipad keyboard which has a previous, next and done button. I have looked at many videos and forums but i cannot relate to any. I am a beginner by the way and i have tried out things by myself, and the furthest i have gotten is the creation of two text boxes :D

    something similar to this http://i.stack.imgur.com/8gOEW.png
    Help would be much appreciated!
    Thanks.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    What have you tried? What code have you written? There's a property called something like accessoryKeyboardView or something that you should assign on the view which uses the keyboard.

    Also, this is the wrong section of the forums. You posted in the Mac Programming section but this is an iOS Programming question.
     
  3. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #3
    ive got this in the .h file at the moment.

    Code:
        
    
    IBOutlet UITextField *textField1;
    IBOutlet UITextField *textField2;
    
        UIToolbar *keyboardToolbar;
    }
    
    @property (nonatomic, retain) IBOutlet UITextField *textField1;
    @property (nonatomic, retain) IBOutlet UITextField *textField2;
    @property (nonatomic, retain) UIToolbar *keyboardToolbar;
    
    - (void)resignKeyboard: (id)sender;
    - (void)previousField: (id)sender;
    - (void)nextField: (id)sender;
    
    this is what i put in my .m file so far

    Code:
    
    - (void)dealloc {
        
        [textField1 release];
        [textField2 release];
        [keyboardToolbar release];
    }
    
    i havent done much obviously but thats because all the tutorials i have seen are for iphone only, and i want this feature to be for ipad. I am very new to this so youll have to bear with me and help me with my silly questions lol.
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    What tutorials are you using? Provide links if they're online or the publisher, the author, the title, and the edition if you got this from a print source.

    (Can we have a help bot that automatically provides these responses or something? Maybe pop up error messages when someone posts something asking for help and is vague - IE, it notices the word "tutorial" or "guide" and a lack of publishing information or a link.)

    Anyways, this probably works exactly the same on an iPad and an iPhone. What makes you think otherwise?
     
  5. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #5
    one of them was a youtube video, here is a link for that:
    http://www.youtube.com/watch?v=YgeuauhsDhQ

    and the other was a blog:
    http://gabriel-tips.blogspot.co.uk/2011/05/input-accessory-view-how-to-add-extra.html

    they are both for adding UItoolbars over the UIkeyboards, and they are both in .xib files. the .xib file may be the same as a .storyboard file, but i cant seem to find the files owner section where you link the textfield1 with the actual text box on the design view.
    Also i thought coding may be different with iPad and it wouldnt recognize some of the commands.
     
  6. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #6
    just need to find out how to link up my textField1 variables with my text box objects now..
     
  7. dpatel, May 26, 2013
    Last edited: May 26, 2013

    dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #7
    anyone able to help? im either doing something wrong or its right in front of my eyes, but i cant link the textbox to the textField1 variable i created. And this error is what comes up when i release the objects:
    Code:
        [textField1 release];         ARC forbids explicit message send of 'release'
        [textField2 release];           'release' is unavailable: not available in automatic reference counting mode
        [keyboardToolbar release];  ARC forbids explicit message send of 'release'
        [super dealloc];                ARC forbids explicit message send of 'dealloc'
    
    I found these examples from the youtube video i linked above, and when he did the same thing, no errors showed.
     
  8. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #8
    You have ARC enabled, remove your dealloc method.

    I suggest reading beginner tutorials/books
     
  9. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #9
    ok i have disabled ARC, but its not letting me conect my UItextfield with my variables:

    Code:
     
        IBOutlet UITextField *textField1;
        IBOutlet UITextField *textField2;
    
    Code:
        @property (nonatomic, retain) IBOutlet UITextField *textField1;
        @property (nonatomic, retain) IBOutlet UITextField *textField2;
    
    i can see the little spots where i can connect the variables to the text-boxes, but they aren't highlighting to show actions......:confused:
     
  10. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #10
    Take a timed screenshot to show us what you mean (using Applications/Utilities/Grab.app if you don't know the shortcut.) I don't understand what you're saying isn't working...
     
  11. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #11
    ok the two screenshots are attached below. Basically the problem for me is that the blue line should connect with the text box and show me a range of segues i can use. Its not showing anything and its not even linking up. The screenshots will show you what i mean
     

    Attached Files:

  12. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #12
    You are confusing connecting outlets to connecting scenes with a segue.

    The screen-shots you posted show you connecting an IBOutlet to a field. That's an important step, but is completely different from linking segues. To connect a segue, you need to have multiple scenes in your storyboard.
     
  13. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #13
    To follow up:

    The blog post you linked spells out in detail how to create and set up a keboard accessory view. To summarize:

    You need to connect an outlet to your text view, as you show in your screen shots.

    You need to connect the delegate property of your text field to your view controller the same way (drag from the delegate property onto "file's owner". Connecting this way tells the text field that your view controller is it's delegate. At key times in the user's interaction with the text view, the text field will try to call methods in your view controller to tell it about what's happening, and/or ask the delegate what it should do next.

    To add an accessory view to your keyboard, you need to implement the method textFieldDidBeginEditing, and in that method, call code that installs the accessory view you created as the text field's accessory view (using the UITextField method setInputAccessoryView.

    If you read the description of the UITextField's inputAccessoryView property, it says:

    The code you posted is just a header file and a dealloc method. You did not post any code that would create or install an accessory view. Did you not understand the instructions in the blog post? They spell out what you need to do in detail.
     
  14. dpatel thread starter macrumors newbie

    Joined:
    May 25, 2013
    #14
    ok thanks for the help, ive connected the text fields to the view controller and it worked, just need to add some more code now, as the custom buttons ive created arent appearing. Cheers!
     

Share This Page