How to dropdown in Objective-c with an arrow sign, when click a button it shows a dropdown list. I need these dropdown twice on a single view controller, have seen many links but when i try to make the second one it shows any error or does not show data in the list. Can anyone could help me?????
Asked
Active
Viewed 5,334 times
-1
-
Check this third party MKDropdownMenu - https://github.com/maxkonovalov/MKDropdownMenu – Apr 18 '17 at 12:50
-
The best way to get help is to show what you are doing and the actual error you are getting. – Phillip Mills Apr 18 '17 at 13:24
-
Actually I haven't done yet but i need a two buttons when we click on it the dropdown list is shown on a view controller. First dropdown should contain list car1,car2,car3 and second dropdown on click should show list of house1,house2,house3. @PhillipMills – Hamza Apr 19 '17 at 06:49
-
@Hamza can u provide ur code ... – NAVEEN KUMAR Apr 19 '17 at 11:42
-
@Hamza my suggestion ... in ios dropdown is not good way ... u can do like this when u click button 1 its goto another TableVC its will show all the data ,when u click that cell it will show as that button text. like wise for button2. – NAVEEN KUMAR Apr 19 '17 at 11:45
-
Sorry @NAVEENKUMAR but i want the list to be shown under that button on the same view controller – Hamza Apr 19 '17 at 12:33
1 Answers
0
understand the concept here..
I created a very simple and easy solution for u .... I hope u can understand it easily.
here my code:
I created but1 to but4 first.
then I created tableview's like in image.
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 {
ImageViewC=@"1";
table1.hidden=NO;
table2.hidden=YES;
table3.hidden=YES;
table4.hidden=YES;
[table1 reloadData];
}
- (IBAction)but2:(UIButton *)sender {
ImageViewC=@"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 {
ImageViewC=@"3";
table1.hidden=YES;
table2.hidden=YES;
table3.hidden=NO;
table4.hidden=YES;
[table3 reloadData];
}
- (IBAction)but4:(UIButton *)sender {
ImageViewC=@"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

NAVEEN KUMAR
- 669
- 6
- 25
-
it is displaying error in didSelectionRowAtIndexPath delegate method that "but1" and "but2" property nit found on object of type'XXTableViewController class'. At the bottom of ur code. @NAVEEN KUMAR – Hamza Apr 20 '17 at 08:11
-
It is working perfect but an issue is coming i want a button un the dropdown list button.When i click the dropdown button list should appear above the under button under it.and scroll the items in the dropdown list @NAVEEN KUMAR – Hamza Apr 21 '17 at 07:48
-
-
sorry for that question I'm new and i don't know how to question. I had checked ur updated answer and tried it. When i place but3 on the table1 it hides under table1 and after run when i click but1 it shows the list of but1 but under that it shows but3 and when i click but3 it shows nothing. @NAVEEN KUMAR – Hamza Apr 24 '17 at 06:03
-
Its working absolutely fine thanks man. Ur skills r too good. @NAVEEN KUMAR – Hamza Apr 24 '17 at 06:44
-
if we want to select a particular item from list to default when we open the page what we want to do? @NAVEEN KUMAR – Hamza Apr 25 '17 at 07:20
-
Suppose i had but1 with list of countries and but2 with the list of cities.Than how can we do that if user select country dubai and the but2 should display cities of dubai. Can u help me to do this in the same scenario. @NAVEEN KUMAR – Hamza Apr 26 '17 at 09:20
-
-
in but1 we have to show countries name like USA , India and China and in but2 i have to show cities but cities should be shown after we select the country. Suppose we select India it and when we click but2 it should display list of cities of india in tableview 2 – Hamza May 03 '17 at 11:06
-
-
-
-
-
and u have only these 3 countries or all countries in the word...? – NAVEEN KUMAR May 03 '17 at 11:28
-
yup 3 country Pakistan, UAE and Oman . In second mail I have send cities of UAE and Oman. @NAVEEN KUMAR – Hamza May 03 '17 at 11:30
-