iphone如何禁用UIBarButtonItem

teu*_*eum 0 iphone uibarbuttonitem

这个问题已被多次询问,但我尝试了所有解决方案,但没有一个解决了我的问题.

这是工具栏创建代码:

- (id)initWithBlogArticle:(BlogArticle *)theArticle
{
    if (self = [super init])
    {
        CustomToolbar* tools = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 48.01)];
        [tools setTintColor:[UIColor colorWithRed:0.62 green:0.70 blue:0.13 alpha:1.0]];

        NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

        UIBarButtonItem* previousArticle = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind
                                                                                         target:self
                                                                                         action:@selector(displayPreviousArticle)];

        [previousArticle setStyle:UIBarButtonItemStyleBordered];
        [buttons addObject:previousArticle];
        [previousArticle release];

        UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil
                                                                                action:nil];
        [buttons addObject:spacer];
        [spacer release];

        UIBarButtonItem *nextArticle = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward 
                                                                                     target:self
                                                                                     action:@selector(displayNextArticle)];
        [nextArticle setStyle:UIBarButtonItemStyleBordered];
        [buttons addObject:nextArticle];
        [nextArticle release];

        [tools setItems:buttons animated:NO];

        [buttons release];

        [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:tools] autorelease]];
        [tools release];

        [self setWebView:[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
        [[self webView] setDelegate:self];
        [self loadBlogArticle:theArticle];

        [self setView:[self webView]];
    }

    return self;
}
Run Code Online (Sandbox Code Playgroud)

我试图在每种可能的方式使用setEnabled:NO并且它永远不会起作用,这让我发疯,因为禁用按钮应该是如此简单......所以这要么是非常复杂,要么我不理解非常基本.

请提前帮助,谢谢.

lol*_*use 6

解:

self.navigationItem.rightBarButtonItem.enabled  = NO/YES;
Run Code Online (Sandbox Code Playgroud)

还有:

self.navigationItem.leftBarButtonItem.enabled  = NO/YES;
Run Code Online (Sandbox Code Playgroud)

适用于iOS 5.