views:

156

answers:

1
UIView *leftButtonItemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

UIImageView *addButtonEmptyImage = [[UIImageView alloc]init];
[addButtonEmptyImage setImage:[UIImage imageNamed:@"black.png"]];
addButtonEmptyImage.frame = CGRectMake(15,0,20,30);

[leftButtonItemView addSubview:addButtonEmptyImage];
[addButtonEmptyImage release];

UIImageView *correctButtonEmptyImage = [[UIImageView alloc]init];
[correctButtonEmptyImage setImage:[UIImage imageNamed:@"black.png"]];
correctButtonEmptyImage.frame = CGRectMake(50,0,20,30);

[leftButtonItemView addSubview:correctButtonEmptyImage];
[correctButtonEmptyImage release];

UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButtonItemView];
[leftButtonItemView release];

self.navigationItem.leftBarButtonItem = leftButtonItem;
[leftButtonItem release];

This is some source of my app. I know NavigationItem has two buttons(left and right). But I hope to make three buttons. so I make one button which use navigationItem and the other button which use a blank view. I want to click correctButtonEmptyImage. But this is in leftButtonItemView. namely, If I clicked the view which contains two images, I woud have seen leftButtonItemView not correctButtonEmptyImage. help me. thanks

+1  A: 

Use UIButtons instead of UIImageViews as the subviews of your container view (leftButtonItemView). Use addTarget:action:forControlEvents: to assign action methods to the buttons.

PS: Please don't just say "It doesn't work" in your question. Tell us more specifically what works and what doesn't. Otherwise we won't be able to help you.

Ole Begemann
Oh, Thanks. I'm so sorry about it.
Beomseok