如何在帶有箭頭符號的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