开发者

How to implement drop down box in iphone?

I have a view and I hv a button on that.I need to have a drop down box on clicking that button. How to implement drop down box?? Drop down box shuold have a table view.When I click rows in table view(after drop down box will open) I want to get text which will be there on the clicked row cell on a view where I had开发者_开发百科 button. How to do that?


Here's a workaround that works for me.

-(IBAction)showDropDownList:(id)sender
{

tableView = [[UITableView alloc] initWithFrame:CGRectMake(7, 135, 200, 0) style:UITableViewStyleGrouped];
        tableView.delegate = self;
        tableView.dataSource = self;

    if (tableState == TableViewStateClosed) {  //enum for identifying tableview state

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect viewRect = self.tableView.frame;
        viewRect.size.height += 150;

        [self.tableView setFrame:CGRectMake(7, 135, 200, viewRect.size.height)];

        [UIView commitAnimations];
        [self.view addSubview:tableView];
        tableState = TableViewStateOpen;
    }
    else if (tableState == TableViewStateOpen) {

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];

        [self.inboxTableView setFrame:CGRectMake(7, 135, 200, 0)];

        [UIView commitAnimations];

        tableState = TableViewStateClosed;
    }
}


There are two ways to achieve this

  1. By using tableview, you can have a tableview with the list of the items which you want to have in your drop down menu. Then in the UITableView's delegate method didselectrow you can have a checkmark for that particular row and then use that particular row's value elsewhere in the project.

  2. You can use Pickerview to achieve drop down list.

Among the two PickerView is advisable.


there is two ways to do it just add one view on ur tableview and then put one tableview or show button on that so that it can see like drop down,call that method on table row selected of button selected on any cell


Here is another alternative. The action sheet is basically a drop down list if you think about it. And if you keep adding buttons to a UIActionSheet it ends up turning into a table. So just have a UIButton (or some event) trigger the UIActionSheet.

Try adding 7 or more buttons to the UIActionSheet and watch it turn into a list. Its convenient.

How to implement drop down box in iphone?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜