gpt4 book ai didi

ios - iOS 上带有 Storyboard 的 TableView 导航栏中的返回、编辑和添加按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:19 30 4
gpt4 key购买 nike

我在实现 tableview 时遇到了一些问题,导航栏上有“返回”、“编辑”和“添加”按钮。通过单击另一个 TableView 的一行可以到达该 TableView ,因此会自动添加“后退”按钮。在 Storyboard 中,我已将“添加”按钮添加到导航栏。通过代码,我添加了“编辑”按钮(我使用了代码,因为如果我在 Storyboard 中添加按钮,我不知道如何重现“编辑”标准行为... ):

self.navigationItem.leftBarButtonItem = self.editButtonItem;

问题在于,在这种方式下,“编辑”按钮隐藏了导航栏上的“后退”按钮。

此时,我有两个问题:

  1. 是否可以使用 Storyboard在导航栏上添加第三个按钮?
  2. 如果我必须以编程方式执行此操作,我知道我可以按如下方式执行此操作:

    UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(width-90,6,50,30)];
    [button setTitle:@"Edit" forState:UIControlStateNormal];
    button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    [self.navigationController.navigationBar addSubview:button];

但是我怎样才能通过代码实现“编辑”按钮的标准行为呢?我的意思是,我单击“编辑”按钮变为“完成”并且行变为可删除...

提前致谢,亚萨

最佳答案

万一其他人碰巧遇到这个问题,解决方案也很简单。 UINavigationItem 有一个 rightItems 属性,它只是一个 UIBarButtonItems 数组。将一个添加按钮和一个编辑按钮放入一个数组中,并将其分配给 rightItems 并完成:-)这是一个示例代码片段:

UITableViewController *table = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
NSArray *barButtons = [NSArray arrayWithObjects:table.editButtonItem, addButton, nil];
table.navigationItem.rightBarButtonItems = barButtons;

关于ios - iOS 上带有 Storyboard 的 TableView 导航栏中的返回、编辑和添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416816/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com