单行中的多个工具栏项

时间:2010-12-15 04:23:16

标签: iphone objective-c ipad uitoolbar uitoolbaritem

我只想在这里创建多个工具栏项目,这就是我所做的......

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);
    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];
}

但它没有在工具栏中显示任何内容......任何建议......?

2 个答案:

答案 0 :(得分:0)

在最后一个for循环中,您将重新声明items数组并反复调用[toolbar setItems:]。就这样做:

[toolbar setItems:barButtonItems animated:NO];

答案 1 :(得分:0)

第二个for循环是什么?
你已经有一个项目数组(barButtonArray) 用这个替换第二个for循环:

[toolbar setItems:barButtonArray animated:NO];