gpt4 book ai didi

ios - 如何从 UITableView 将按钮添加到详细 View 的顶部栏

转载 作者:行者123 更新时间:2023-12-01 17:34:52 24 4
gpt4 key购买 nike

当从 UITableView 中选择一个项目时,会加载一个详细 View ,该 View 顶部有一个横幅栏,上面有一个后退按钮,用于导航回表格。

如何将其他按钮添加到该横幅栏?

最佳答案

正如安德鲁所说,您可以将自定义 View 添加到导航栏。例如,如果您希望在导航栏的右侧添加多个按钮,您可以执行以下操作:

// right side of nav bar
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 106, 44)];
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];

UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self
action:@selector(deleteAction:)];
deleteButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:deleteButton];
[deleteButton release];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancelAction:)];
cancelButton.style = UIBarButtonItemStylePlain;
[buttons addObject:cancelButton];
[cancelButton release];

[toolbar setItems:buttons animated:NO];
toolbar.barStyle = -1;
[buttons release];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[toolbar release];

如果您需要更多或更宽的按钮,请确保调整宽度(上面的 106),然后为选择器提供方法(上面的 deleteAction: 和 cancelAction: )。

关于ios - 如何从 UITableView 将按钮添加到详细 View 的顶部栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255859/

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