-2

i have created a toolbar as below shown code and now i dont knw how to add the items to it.

- (void)viewDidLoad
{
[super viewDidLoad];    
UIToolbar *toolbar = [[UIToolbar alloc] init];    
toolbar.frame = CGRectMake(0, 418, 350, 44);   
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[[UIBarButtonItem alloc] init] autorelease]];
[toolbar setItems:items animated:YES];
[items release];
[self.view addSubview:toolbar];
[toolbar release];
}
reddy
  • 13
  • 10

2 Answers2

0

Try this code

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item"     style:UIBarButtonItemStyleBordered  target:self action:@selector(action:)];

NSArray *items = [NSArray arrayWithObjects: customItem, nil];
[toolbar setItems:items animated:NO];

[customItem release];

You can also refer to this link: How to create this toolbar programmatically

Please do google search and Stack Overflow search before posting.

Community
  • 1
  • 1
Saurabh Shukla
  • 1,368
  • 3
  • 14
  • 26
0

use [self setToolbarItems: buttons animated:NO]; as u want to set toolbaritems and uiviewcontroller has toolbar itself.

BhushanVU
  • 3,455
  • 1
  • 24
  • 33