我想更改 SLComposeServiceViewController 中发布按钮的标题。我设法得到了 UIButton:
NSArray* subviews =[self.navigationController.navigationBar subviews];
UIButton* postButton =[subviews lastObject];
我试图这样设置标题:
[postButton setTitle:@"Save" forState:UIControlStateNormal];
但标题没有改变。
谁能帮我这个?
我在 iPad 上看到了 Evernote 的共享扩展,它看起来像这样:
更新
我的解决方案:
我找到了我的问题的解决方案,我删除了原始导航栏并创建了自定义导航栏。
我有两个导航栏:1.带有“取消”\“保存”按钮 2.带有“返回”按钮
我在导航到其他视图控制器时更改它们(在我的情况下,我需要上传文件,用户需要从列表中选择位置)
注意:如果您不实施configurationItems
,您只需要第一个导航栏。(只需调用设置自定义导航栏viewDidAppear
所以我的代码在这里:
@property (strong, nonatomic) UINavigationBar *customNavBar;
-(void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.customNavBar = [[UINavigationBar alloc] initWithFrame:self.navigationController.navigationBar.bounds];
[self.navigationController.navigationBar removeFromSuperview];
[self.navigationController.view addSubview:self.customNavBar];
[self setCancelSaveNavigationItem];
}
setCancelSaveNavigationItem--> 从 shareViewController 的 viewDidAppear 调用
-(void)setCancelSaveNavigationItem
{
UINavigationItem *newItem = [[UINavigationItem alloc] init];
UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonTapped:)];
UIBarButtonItem *saveBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done",nil) style:UIBarButtonItemStyleDone target:self action:@selector(saveButtonTapped:)];
newItem.leftBarButtonItem = cancelBarButtonItem;
newItem.rightBarButtonItem = saveBarButtonItem;
[self.customNavBar setItems:@[newItem]];
[self.navigationItem setBackBarButtonItem:cancelBarButtonItem];
[self.navigationItem setRightBarButtonItem:saveBarButtonItem];
if(self.item.value == nil){
saveBarButtonItem.enabled = NO;
}
}
setBackNavigationItem--> 在函数中调用configurationItems
--> 在self.item.tapHandler
函数中
-(void)setBackNavigationItem
{
UINavigationItem *newItem = [[UINavigationItem alloc] init];
UIBarButtonItem *selectBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Select",nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectButtonTapped:)];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"❮ %@", NSLocalizedString(@"Back",nil)] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped:)];
newItem.leftBarButtonItem = backBarButtonItem;
newItem.rightBarButtonItem = selectBarButtonItem;
[self.customNavBar setItems:@[newItem]];
[self.navigationItem setBackBarButtonItem:backBarButtonItem];
[self.navigationItem setRightBarButtonItem:selectBarButtonItem];
}
轻按的手柄按钮:
- (void)backButtonTapped:(id)sender {
if([self.navigationController.viewControllers count] ==2){
[self setCancelSaveNavigationItem];
}
[self.navigationController popViewControllerAnimated:YES];
}
- (void)cancelButtonTapped:(id)sender {
[self cancel];
}
- (void)selectButtonTapped:(id)sender {
...
[self setCancelSaveNavigationItem];
[self popConfigurationViewController];
}
- (void)saveButtonTapped:(id)sender {
...
[self cancel];
}
它对我有用!!!
结果: