开发者

Multiple toolbar items in a single row

i just want to create multiple toolbar items in a single row here what i did...

NSMutableArray *barButtonArray = [[NSMutableArray alloc] init];
for (int i=0; i<[[State getSubCategoryids] count]; i++) {

    NSString *nameString = [NSString stringWithFormat:@"%@",[[State getSubCategoryNames] objectAtIndex:i]];
    NSLog(@"nameString: %@", nameString)开发者_StackOverflow;
    UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithTitle:nameString style:UIBarButtonItemStyleBordered target:nil action:@selector(productImages)];
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                              target:nil
                                                                              action:nil];
    [barButtonArray addObject:customBarButton];
    [barButtonArray addObject:flexItem];

    [flexItem release];
    [customBarButton release];


}




for (int i = 0; i<[barButtonArray count]; i++) {
    NSLog(@"barbutton items for loop");
    NSArray *items = [NSArray arrayWithObjects:[barButtonArray objectAtIndex:i],nil];
    NSLog(@"items: %@", items);
    [toolbar setItems:items animated:NO];
}

but it is not showing anything in toolbar ...... any suggestions...?


What is the second for-loop for?
You already have an array of items (barButtonArray).
Replace the second for-loop with this:

[toolbar setItems:barButtonArray animated:NO];


In your last for loop you are redeclaring the items array and calling [toolbar setItems:] over and over. Just do this:

[toolbar setItems:barButtonItems animated:NO];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜