简体   繁体   English

条形按钮项未显示

[英]Bar button items not showing

I have implemented a Detail Disclosure Button on my table view cell to edit existing texts in the cells. 我已经在表格视图单元中实现了“详细信息披露按钮”,以编辑单元中的现有文本。 But the problem is that when I click on the Detail Disclosure Button it shows the existing text field but without any 'Edit' and 'Cancel' bar button items on the top. 但是问题是,当我单击详细信息披露按钮时,它显示了现有的文本字段,但顶部没有任何“编辑”和“取消”栏按钮项。 I have given the segue identifier name as 'EditItem'. 我已将segue标识符名称命名为“ EditItem”。 I also have another segue which is named 'AddItem' that works properly and shows 'Edit' and 'Cancel' bar button item. 我还拥有另一个名为“ AddItem”的功能,可以正常工作并显示“编辑”和“取消”栏按钮项。 I have checked the code many times to find out the problem but didn't find any solution. 我已经多次检查代码以找出问题,但没有找到任何解决方案。 I want to know how to fix this problem. 我想知道如何解决此问题。

I'm using Xcode 6 beta 6 SDK. 我正在使用Xcode 6 beta 6 SDK。

Your problem is that you are not adding the item the same way as you are editing the item. 您的问题是您添加的项目与编辑项目的方式不同。 Look at this: 看这个:

if ([segue.identifier isEqualToString:@"AddItem"]){
        UINavigationController *navigation = segue.destinationViewController;
        AddItemViewController *controller =(AddItemViewController *) navigation.topViewController;
        controller.delegate = self;
    } else if ([segue.identifier isEqualToString:@"EditItem"]){
        UINavigationController *navigation = segue.destinationViewController;
        AddItemViewController *controller = (AddItemViewController *)navigation;
        controller.delegate = self;

        //
        NSIndexPath *indexpath = [self.tableView indexPathForCell:sender];
        controller.itemToEdit = _items[indexpath.row];

    }

Notice that for the AddItem segue you are getting the view controller like this: 注意,对于AddItem segue,您将获得如下所示的视图控制器:

AddItemViewController *controller =(AddItemViewController *) navigation.topViewController;

But for the EditItem segue you are getting it like this: 但是对于EditItem segue,您将获得如下所示的信息:

AddItemViewController *controller =(AddItemViewController *) navigation;

In your storyboard, the AddItem segue is connected to a navigation controller, which is then connected to your AddViewController , but the EditItem segue goes directly to the AddViewController . 在您的情节AddViewControllerAddItem segue连接到导航控制器,然后将其连接到AddViewController ,但是EditItem segue直接进入AddViewController

Connecting EditItem to the same navigation controller AddItem is connected to should fix your problem. EditItem连接到同一导航控制器,将AddItem连接到应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM