删除 ABPeoplePickerNavigationController 中的取消按钮。 iOs 4.x 中的奇怪行为
我想删除 ABPeoplePickerNavigationController 导航栏中的取消按钮,因为我想要一个添加按钮。 我以这种方式自定义了导航控制器委托:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
switch ([navigationController.viewControllers count]) {
case 0: {
viewController.navigationItem.rightBarButtonItem = nil;
break;
}
case 1: {
viewController.navigationItem.rightBarButtonItem = nil;
break;
}
case 2: {
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson:)];
[viewController.navigationItem setRightBarButtonItem:addButtonItem animated:NO];
[addButtonItem release];
UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
[viewController.navigationItem setLeftBarButtonItem:cancelButtonItem animated:NO];
[cancelButtonItem release];
NSLog(@"View 2 %@",viewController.navigationItem.rightBarButtonItem);
break;
}
case 3: {
UIBarButtonItem *editButtonItem;
if ([viewController isKindOfClass:[ABPersonViewController class]]) {
editButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPerson:)];
self.personView = (ABPersonViewController*) viewController;
self.personView.allowsEditing = YES;
self.personView.personViewDelegate = self;
[viewController.navigationItem setRightBarButtonItem:editButtonItem animated:NO];
[editButtonItem release];
} else {
// ABPersonNewViewController
//No need to add codes here
}
break;
}
default: {
break;
}
}
它在 iOs 3.x 和 iOs 5.x 中工作正常,但在 iOS 4.x 中,当联系人列表出现时,导航栏中总是有取消按钮,但如果我选择联系然后我回到第一个视图控制器,添加按钮将出现。
如何解释仅在 iOS 4.x 中的这种奇怪行为?
I would like to remove the cancel button in the navigation bar of ABPeoplePickerNavigationController because I want to have an add button.
I customized the navigation controller delegate in this way:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
switch ([navigationController.viewControllers count]) {
case 0: {
viewController.navigationItem.rightBarButtonItem = nil;
break;
}
case 1: {
viewController.navigationItem.rightBarButtonItem = nil;
break;
}
case 2: {
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson:)];
[viewController.navigationItem setRightBarButtonItem:addButtonItem animated:NO];
[addButtonItem release];
UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
[viewController.navigationItem setLeftBarButtonItem:cancelButtonItem animated:NO];
[cancelButtonItem release];
NSLog(@"View 2 %@",viewController.navigationItem.rightBarButtonItem);
break;
}
case 3: {
UIBarButtonItem *editButtonItem;
if ([viewController isKindOfClass:[ABPersonViewController class]]) {
editButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPerson:)];
self.personView = (ABPersonViewController*) viewController;
self.personView.allowsEditing = YES;
self.personView.personViewDelegate = self;
[viewController.navigationItem setRightBarButtonItem:editButtonItem animated:NO];
[editButtonItem release];
} else {
// ABPersonNewViewController
//No need to add codes here
}
break;
}
default: {
break;
}
}
It works fine in iOs 3.x and iOs 5.x, but in iOS 4.x I always have the cancel button in the navigation bar when the contacts list appears but if I select a contact then I go back to the first view controller the add button will appear.
How can explain this strange behavior only in iOS 4.x ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案:
}
所以如果你想删除 iOs 4.x 中的取消按钮,你必须添加这一行:
[选择器设置允许取消:否];
我收到了来自编译器的警告,但现在取消按钮在 iOS 4.x 中被删除了
I found the solution:
}
So if you want to remove the cancel button in iOs 4.x you have to add this line:
[picker setAllowsCancel:NO];
I received a warning from the compiler, but now the cancel button is removed in iOS 4.x
//picker是ABPeoplePickerNavigationController的一个对象。
//picker is an object of ABPeoplePickerNavigationController.