如何在带有箭头符号的Objective-c中下拉菜单,点击按钮时显示下拉列表。我需要这些下拉菜单两次在单个视图控制器上,看到很多链接,但是当我尝试使第二个显示任何错误或不显示列表中的数据。任何人都可以帮我吗?iOS中使用Objective-C下拉菜单
-2
A
回答
0
了解这里的概念..
我创建了U A非常简单和容易的解决方案....我希望你可以很容易地理解它。
这里我的代码:
我创建but1先but4。
然后我在图像中创建了tableview。
ViewController.h
//button Actions
- (IBAction)but1:(UIButton *)sender;
- (IBAction)but2:(UIButton *)sender;
- (IBAction)but3:(UIButton *)sender;
- (IBAction)but4:(UIButton *)sender;
//table properties
@property (weak, nonatomic) IBOutlet UITableView *table1;
@property (weak, nonatomic) IBOutlet UITableView *table2;
@property (weak, nonatomic) IBOutlet UITableView *table3;
@property (weak, nonatomic) IBOutlet UITableView *table4;
//button properties
@property (weak, nonatomic) IBOutlet UIButton *but1;
@property (weak, nonatomic) IBOutlet UIButton *but2;
@property (weak, nonatomic) IBOutlet UIButton *but3;
@property (weak, nonatomic) IBOutlet UIButton *but4;
ViewController.m
#import "ViewController.h"
@interface ViewController()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource>{
// UIImagePickerController *picker;
NSString *ImageViewC;
NSArray *data;
NSArray *data1;
}
@end
@implementation ViewController
@synthesize table1,table2,table3,table4;
- (void)viewDidLoad {
[super viewDidLoad];
data=[[NSArray alloc]initWithObjects:@"car1",@"car2",@"car1",@"car2", nil];
data1=[[NSArray alloc]initWithObjects:@"house1",@"house2",@"house3",@"house4", nil];
table2.dataSource=self;
table1.dataSource=self;
table3.dataSource=self;
table4.dataSource=self;
table2.delegate=self;
table1.delegate=self;
table3.delegate=self;
table4.delegate=self;
table1.hidden=YES;
table2.hidden=YES;
table3.hidden=YES;
table4.hidden=YES;
// picker = [[UIImagePickerController alloc]init];
// picker.delegate=self;
//
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)but1:(UIButton *)sender {
[email protected]"1";
table1.hidden=NO;
table2.hidden=YES;
table3.hidden=YES;
table4.hidden=YES;
[table1 reloadData];
}
- (IBAction)but2:(UIButton *)sender {
[email protected]"2";
table1.hidden=YES;
table2.hidden=NO;
table3.hidden=YES;
table4.hidden=YES;
[table2 reloadData];
// [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// [self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)but3:(UIButton *)sender {
[email protected]"3";
table1.hidden=YES;
table2.hidden=YES;
table3.hidden=NO;
table4.hidden=YES;
[table3 reloadData];
}
- (IBAction)but4:(UIButton *)sender {
[email protected]"4";
table1.hidden=YES;
table2.hidden=YES;
table3.hidden=YES;
table4.hidden=NO;
[table4 reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([ImageViewC isEqualToString:@"1"])
return [data count];
else
return [data1 count];
}
// Customize the appearance of table view cells.
- (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];
}
if ([ImageViewC isEqualToString:@"1"]) {
cell.textLabel.text = [data objectAtIndex:indexPath.row];
}else if([ImageViewC isEqualToString:@"2"]){
cell.textLabel.text = [data1 objectAtIndex:indexPath.row];
}else if ([ImageViewC isEqualToString:@"3"]){
cell.textLabel.text=[data objectAtIndex:indexPath.row];
}else{
cell.textLabel.text=[data1 objectAtIndex:indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@",selectedCell.textLabel.text);
if ([ImageViewC isEqualToString:@"1"]) {
[self.but1 setTitle:[NSString stringWithFormat:@"%@",selectedCell.textLabel.text] forState:UIControlStateNormal];
}else if ([ImageViewC isEqualToString:@"2"]){
[self.but2 setTitle:[NSString stringWithFormat:@"%@",selectedCell.textLabel.text] forState:UIControlStateNormal];
}else if ([ImageViewC isEqualToString:@"3"]){
[self.but3 setTitle:[NSString stringWithFormat:@"%@",selectedCell.textLabel.text] forState:UIControlStateNormal];
}else{
[self.but4 setTitle:[NSString stringWithFormat:@"%@",selectedCell.textLabel.text] forState:UIControlStateNormal];
}
table1.hidden=YES;
table2.hidden=YES;
table3.hidden=YES;
table4.hidden=YES;
}
@end
相关问题
- 1. 下拉菜单为IOS应用程序
- 2. bootstrap下拉菜单不适用于iOS
- 3. iOS提醒中的下拉菜单
- 4. 使用jquery下拉菜单
- 5. Animate.css使用下拉菜单
- 6. 使用下拉菜单
- 7. 使用日期过滤下拉菜单到下拉菜单
- 8. 如何使css下拉菜单中的一个下拉菜单
- 9. 使用swift在iOS应用程序中创建下拉菜单
- 10. 如何在ios的uitextfield中使用下拉菜单?
- 11. 在MVC中使用下拉菜单5
- 12. 从下拉菜单中选择下拉菜单中的数值
- 13. 下拉菜单
- 14. 下拉菜单?
- 15. 下拉菜单
- 16. 下拉菜单
- 17. 下拉菜单
- 18. 下拉菜单
- 19. 下拉菜单
- 20. 下拉菜单
- 21. 下拉菜单
- 22. 下拉菜单
- 23. CSS3下拉菜单和iOS问题
- 24. 如何使下拉菜单
- 25. Javascript:根据其他下拉菜单禁用下拉菜单
- 26. 在下拉菜单中更改CSS下拉菜单
- 27. 从下拉菜单中删除下拉菜单(选择)?
- 28. Ember视图下拉菜单下拉菜单中有空标签
- 29. 在下拉菜单中转换CSS下拉菜单
- 30. w3css - 下拉菜单中的可靠下拉菜单
检查该第三方MKDropdownMenu - https://github.com/maxkonovalov/MKDropdownMenu – 2017-04-18 12:50:29
最好的方式来获得帮助是显示你正在做的事情和你得到的实际错误。 –
其实我还没有完成,但我需要一个两个按钮,当我们点击它时,下拉列表显示在视图控制器上。第一个下拉列表应包含列表car1,car2,car3,第二个下拉列表应显示house1,house2,house3的列表。 @PhillipMills – Hamza