Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从UITableView向局部视图的顶栏添加按钮_Ios_Uitableview - Fatal编程技术网

Ios 如何从UITableView向局部视图的顶栏添加按钮

Ios 如何从UITableView向局部视图的顶栏添加按钮,ios,uitableview,Ios,Uitableview,选择UITableView中的项目时,将加载一个详细视图,该视图顶部有一个横幅栏,上面有一个返回按钮,用于导航回表格 如何将其他按钮添加到该横幅栏?根据您的描述,听起来您已经正确设置了UINavigationController。您所描述的“横幅栏”正确地称为导航栏 在详图视图中,可以使用: UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePla

选择UITableView中的项目时,将加载一个详细视图,该视图顶部有一个横幅栏,上面有一个返回按钮,用于导航回表格


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

根据您的描述,听起来您已经正确设置了UINavigationController。您所描述的“横幅栏”正确地称为导航栏

在详图视图中,可以使用:

UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePlain target:self action:@selector(onHiMom:)] autorelease];
self.navigationItem.rightBarButtonItem = button;

您还可以添加自定义视图(而不是按钮)以及一些其他设置。我建议大家浏览一下UINavigationItem、UINavigationBar和UIBarButtonItem的文档,了解一些想法。

根据您的描述,听起来您已经正确设置了UINavigationController。您所描述的“横幅栏”正确地称为导航栏

在详图视图中,可以使用:

UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePlain target:self action:@selector(onHiMom:)] autorelease];
self.navigationItem.rightBarButtonItem = button;

您还可以添加自定义视图(而不是按钮)以及一些其他设置。我建议浏览UINavigationItem、UINavigationBar和UIBarButtonItem的文档以获取想法。

正如Andrew所说,您可以向导航栏添加自定义视图。例如,如果要在导航栏的右侧添加多个按钮,可以执行以下操作:

// 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:删除操作)。

正如Andrew所说,您可以向导航栏添加自定义视图。例如,如果要在导航栏的右侧添加多个按钮,可以执行以下操作:

// 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:删除操作)。

。谢谢当然,我真正想做的是在导航栏中添加三个单独的按钮。似乎要这样做,我必须设置一些更复杂的东西,比如分段控件?我最近在这里看到了类似的东西。您可以使用自定义视图(例如包含三个按钮)创建BarButtonItem,也可以使用自定义视图(通过导航项的titleView属性)替换标题视图,并将按钮放在其中。谢谢当然,我真正想做的是在导航栏中添加三个单独的按钮。似乎要这样做,我必须设置一些更复杂的东西,比如分段控件?我最近在这里看到了类似的东西。您可以使用自定义视图(例如包含三个按钮)创建BarButtonItem,也可以使用自定义视图替换标题视图(通过导航项的titleView属性)并将按钮放在其中。完美。戴夫:如果答案对你有帮助的话,你能单击上/下数字下面的小复选框,将其标记为已接受的答案吗?谢谢,太好了。戴夫:如果答案对你有帮助的话,你能单击上/下数字下面的小复选框,将其标记为已接受的答案吗?谢谢