如何在导航栏中以编程方式添加下拉菜单?

时间:2022-04-26 07:41:17

can anyone tell. how to create drop down menu in iPhone,and i want add drop down menu in navigateion bar (my concept is sorting(filter) so i want three buttons in menu name,title,description .....) 如何在导航栏中以编程方式添加下拉菜单?

任何人都可以告诉如何在iPhone中创建下拉菜单,我想在导航栏中添加下拉菜单(我的概念是排序(过滤)所以我想在菜单名称,标题,描述中有三个按钮.....)

3 个解决方案

#1


1  

You can use a UIPopoverController for iPhone.

您可以使用UIPopoverController for iPhone。

It's available here.

它可以在这里找到。

In the popover you can add a UIPickerView and there's the drop-down. Basically , on iPhone you can use a UITableView or UIPickerView to simulate a drop down. And to place it in a nice container you can use the above mentioned popover.

在popover中你可以添加一个UIPickerView,下面是下拉列表。基本上,在iPhone上你可以使用UITableView或UIPickerView来模拟下拉菜单。并将它放在一个漂亮的容器中,你可以使用上面提到的popover。

#2


0  

There is no such a component in iOS, so you need to create it by yourself. You can do that by adding a UIView under your button, and animate it. Something like...

iOS中没有这样的组件,因此您需要自己创建它。您可以通过在按钮下添加UIView并为其设置动画来实现。就像是...

 [self.view addSubview:myMenu];
[myMenu setFrame:CGRectMake(100,30,150,0)];
[UIView animateWithDuration:0.4 animation:^{
    [myMenu setFrame:CGRectMake(100,30,150,200)];
}];

#3


0  

 //on Drop down button click  
 -(IBAction)btnDropdownPressed:(id)sender{
if (![popoverController isPopoverVisible]) 
{
  PopOverViewController *attShow=[[PopOverViewController alloc]initWithNibName:@"PopOverViewController" bundle:nil];
    NSLog(@"arrFiles==%@",arrFiles);

    attShow.arrFiles=arrFiles;
  {
    popoverController=[[[UIPopoverController alloc]initWithContentViewController:attShow] retain];
    [popoverController setPopoverContentSize:CGSizeMake(500,250)];

    [popoverController presentPopoverFromRect:CGRectMake(0,0, 500, 30) inView:btnMore permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

}else {
    [popoverController dismissPopoverAnimated:YES];
   }

}

PopOverViewController.h

PopOverViewController.h

  {
IBOutlet UITableView *tblView;
NSArray *arrFiles;
}
@property(nonatomic,retain)NSArray *arrFiles;

PopOverViewController.m

PopOverViewController.m

 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
   {
return [self.arrFiles count];
  }

 -(CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
return 40;
   }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

cell.textLabel.text=[self.arrFiles objectAtIndex:indexPath.row];
cell.textLabel.font=[UIFont fontWithName:@"Arial" size:14.0f];
cell.selectionStyle=UITableViewCellSelectionStyleNone;

return cell;
} 

#1


1  

You can use a UIPopoverController for iPhone.

您可以使用UIPopoverController for iPhone。

It's available here.

它可以在这里找到。

In the popover you can add a UIPickerView and there's the drop-down. Basically , on iPhone you can use a UITableView or UIPickerView to simulate a drop down. And to place it in a nice container you can use the above mentioned popover.

在popover中你可以添加一个UIPickerView,下面是下拉列表。基本上,在iPhone上你可以使用UITableView或UIPickerView来模拟下拉菜单。并将它放在一个漂亮的容器中,你可以使用上面提到的popover。

#2


0  

There is no such a component in iOS, so you need to create it by yourself. You can do that by adding a UIView under your button, and animate it. Something like...

iOS中没有这样的组件,因此您需要自己创建它。您可以通过在按钮下添加UIView并为其设置动画来实现。就像是...

 [self.view addSubview:myMenu];
[myMenu setFrame:CGRectMake(100,30,150,0)];
[UIView animateWithDuration:0.4 animation:^{
    [myMenu setFrame:CGRectMake(100,30,150,200)];
}];

#3


0  

 //on Drop down button click  
 -(IBAction)btnDropdownPressed:(id)sender{
if (![popoverController isPopoverVisible]) 
{
  PopOverViewController *attShow=[[PopOverViewController alloc]initWithNibName:@"PopOverViewController" bundle:nil];
    NSLog(@"arrFiles==%@",arrFiles);

    attShow.arrFiles=arrFiles;
  {
    popoverController=[[[UIPopoverController alloc]initWithContentViewController:attShow] retain];
    [popoverController setPopoverContentSize:CGSizeMake(500,250)];

    [popoverController presentPopoverFromRect:CGRectMake(0,0, 500, 30) inView:btnMore permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

}else {
    [popoverController dismissPopoverAnimated:YES];
   }

}

PopOverViewController.h

PopOverViewController.h

  {
IBOutlet UITableView *tblView;
NSArray *arrFiles;
}
@property(nonatomic,retain)NSArray *arrFiles;

PopOverViewController.m

PopOverViewController.m

 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
   {
return [self.arrFiles count];
  }

 -(CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
return 40;
   }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

cell.textLabel.text=[self.arrFiles objectAtIndex:indexPath.row];
cell.textLabel.font=[UIFont fontWithName:@"Arial" size:14.0f];
cell.selectionStyle=UITableViewCellSelectionStyleNone;

return cell;
}