Tôi có một chế độ xem tùy chỉnh bên trong một UIBarButtonItem
, được thiết lập bằng cách gọi -initWithCustomView
. Mục nút thanh của tôi hiển thị tốt, nhưng khi tôi nhấn vào nó, nó không thực hiện hành động trên đối tượng mục tiêu của tôi.
Đây là mã của tôi:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage.png"]];
UIBarButtonItem *bbItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];
self.navigationItem.leftBarButtonItem = bbItem;
[imageView release];
[bbItem setTarget:self];
[bbItem setAction:@selector(deselectAll)];
UIBarButtonItem
kế thừa từUIBarItem
vàNSObject
vì vậy nó không biết bất cứ điều gì về cảm ứng. Sẽ rất tuyệt nếu các tài liệu đề cập rằng các thuộc tínhaction
vàtarget
chỉ áp dụng nếu chế độ xem tùy chỉnh là UIButton.