-1

如何在 iOS 中创建一个好看的下拉菜单。当用户单击导航栏中的按钮时,它应该打开。

我尝试创建一个表,但收到错误静态表视图仅在嵌入 UITableViewController 实例时才有效。如果我使用 UITableViewController,那么它必须是全宽的。

4

3 回答 3

1

也许您可以尝试使用 CollectionView 而不是 TableView,如果您需要 iOS 4+ 的支持,PSTCollectionView 是一个不错的选择 :)

于 2013-09-10T22:56:05.827 回答
1

What I did is added a Button and on button tap one table view is shown, whenever any row is selected that row title is set to button title.

- (void)addOrganizationButton {

self.organizationButton =  [UIUtils createButtonWithFrame:CGRectMake(203,115,451,38)
                     titleText:@"Organization"
                          type:UIButtonTypeCustom
                   normalImage:nil selectedImage:nil
                        target:self
                          view:self.registerView
                           tag:0
                      selector:@selector(organizationButtonTap)];
self.organizationButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[self.organizationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.organizationButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.organizationButton.layer.borderWidth = 1;
}

//在按钮点击时显示表格视图

- (void)organizationButtonTap {
self.organizationTable = [[UITableView alloc]initWithFrame:CGRectMake(203,153, 451,220)];
self.organizationTable.layer.borderWidth = 1;
self.organizationTable.dataSource = self;
self.organizationTable.delegate = self;

[UIView animateWithDuration:1
                      delay:0.0
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     CGRect frame = self.organizationTable.frame;
                     frame.size.height = 220;
                     self.organizationTable.frame = frame;
                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

[self.registerView addSubview:self.organizationTable];
}

//表视图委托

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 1;//to be changed
}

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{

return 3;//get dictionary count
}

- (UITableViewCell *) tableView:(UITableView *)tableView
      cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell;
NSString *cellIdentifier=@"Cell Identifier";
cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil){

    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryNone;

}


cell.textLabel.text = [NSString stringWithFormat:
                       @"Section %ld, Cell %ld",
                       (long)indexPath.section,
                       (long)indexPath.row];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


[self.organizationButton setTitle:@"faf" forState:UIControlStateNormal];
[UIView animateWithDuration:1
                      delay:0.0
                    options:  UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     CGRect frame = self.organizationTable.frame;
                     frame.size.height = 0;
                     self.organizationTable.frame = frame;
                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

}
于 2014-01-08T05:08:09.057 回答
0

您可以为此准备一个自定义视图并将其作为子视图添加到您的 ViewController 中。使用 UIView 动画来模拟“下拉”效果。

于 2013-09-10T22:48:21.293 回答