add UITextField and FixedSpace programatically to toolbar

Discussion in 'iOS Programming' started by AbhishekApple, Dec 13, 2010.

  1. AbhishekApple macrumors member

    Aug 5, 2010
    I have following code where in only search bar,fixedspacebar is visible on the toolbar but uitextfield is not visible.....
    Also fixedspace bar should not be visible in runtime but it is visible and can be tapped as button....
    - (void)viewDidLoad {
        [super viewDidLoad];
    	//self.view.backgroundColor =[UIColor blackColor];
    	toolBar =[[UIToolbar alloc]init];
    	srcBar = [[UISearchBar alloc] init];
    	txtPrice = [[UITextField alloc] init];
    	btnSearchBar = [[UIBarButtonItem alloc]initWithCustomView:srcBar];
    	btntxtPriceBar = [[UIBarButtonItem alloc]initWithCustomView:txtPrice];
    	fixedBar = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    	[txtPrice setPlaceholder:@"helloc"];
    	[toolBar setItems:[NSArray arrayWithObjects:btnSearchBar,btntxtPriceBar,fixedBar,nil]];
    	btnSearchBar.width = 200;
    	btntxtPriceBar.width = 200;
            fixedBar.width = 410;
    Please suggest on this.....
  2. ianray macrumors 6502

    Jun 22, 2010
    btntxtPriceBar.width = 200;
    [COLOR="Red"][txtPrice sizeToFit];[/COLOR]
    [toolBar setItems:[NSArray arrayWithObjects:btnSearchBar,btntxtPriceBar,fixedBar,nil]];
    This works. Hope this helps :)
  3. AbhishekApple thread starter macrumors member

    Aug 5, 2010
    Thanks ianray.....but the FixedSpace button problem is not yet resolved...
    FixedSpace button is visible on runtime and can be tapped....which property needs to be set for it....
  4. dejo, Dec 15, 2010
    Last edited: Dec 15, 2010

    dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Can you post the entire viewDidLoad method?


    P.S. For the fixed space, you should use the following instead:

    If you had looked at the possible choices for style: in your call to initWithTitle:style:target:action:, you'd see that UIBarButtonSystemItemFixedSpace is not a valid choice.
  5. AbhishekApple thread starter macrumors member

    Aug 5, 2010
    Thanks dejo this worked....ur explanation helped...

Share This Page