这让我很烦!我只是想以编程方式在我的导航栏上添加一个右侧的“flash”按钮,无论出于何种原因,我都无法让它出现。我的代码如下。谁能帮我?提前致谢。
//Note: flashButton is declared as a UIButton property in .h, and synthesized in .m
UIView *flashContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)];
[flashButton addTarget:self action:@selector(toggleTorch) forControlEvents:UIControlEventTouchUpInside];
[flashButton setBackgroundImage: [UIImage imageNamed:@"FlashIconInactive_small.png"] forState:UIControlStateNormal];
[flashButton setBackgroundImage: [UIImage imageNamed:@"FlashIconActive_small.png"] forState:UIControlStateHighlighted];
[flashContainer addSubview:flashButton];
[flashButton sizeToFit];
UIBarButtonItem *flashButtonItem = [[UIBarButtonItem alloc] initWithCustomView:flashContainer];
scannerVC.delegate = self;
scannerVC.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelTapped)];
[[scannerVC navigationItem] setRightBarButtonItem:flashButtonItem];