1

I have a menu like

enter image description here

It shows only select button but I want when I select Hello 2 open Hello2 view controller.

My code :

enter code here

 - (IBAction)selectClicked:(id)sender {
NSArray * arr = [[NSArray alloc] init];
arr = [NSArray arrayWithObjects:@"Hello 0", @"Hello 1", @"Hello 2", @"Hello 3", @"Hello   4", @"Hello 5", @"Hello 6", @"Hello 7", @"Hello 8", @"Hello 9",nil];
NSArray * arrImage = [[NSArray alloc] init];
arrImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"apple.png"], [UIImage    imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], nil];
if(dropDown == nil) {
    CGFloat f = 200;
    dropDown = [[NIDropDown alloc]showDropDown:sender :&f :arr :arrImage :@"down"];
    dropDown.delegate = self;
}
else {
    [dropDown hideDropDown:sender];
    [self rel];
}
 }

-(void)rel{
//    [dropDown release];
  dropDown = nil;
 }
5
  • set some tag to the button & as per the button selection, check which button is clicked using tag & open view controller accordingly. Commented May 29, 2013 at 9:10
  • What is NIDropDown class? is there a didSelectRowAtIndexPath method of table view present? Commented May 29, 2013 at 9:18
  • @SharanyaKM Yes there is this method in NIDropDown.m pastie.org/7978703 Commented May 29, 2013 at 9:21
  • You should mention that you using thirdparty and copy and paste from example project: github.com/BijeshNair/NIDropDown/blob/master/NIDropDown/… Commented May 29, 2013 at 9:21
  • Yes it is same sample.I want to edit this sample for when I select open selected view controller Commented May 29, 2013 at 9:23

4 Answers 4

4

The delegate method get invoked in the selection of table

- (void) niDropDownDelegateMethod: (NIDropDown *) sender 

Find out which option is pressed from there and implement the push method

The problem is the code doesnt provide method for getting the value selected.You have to look into that custom class NIDropDown and add a value returning the selected index

Solution

.h add

@property (nonatomic, assign) NSInteger *selectedIndex;

.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     self.selectedIndex=indexPath.row;//Add this line
    [self myDelegate];
}

and in viewcontroller

- (void) niDropDownDelegateMethod: (NIDropDown *) sender {
    NSLog(@"%d",sender.selectedIndex);
}
Sign up to request clarification or add additional context in comments.

Comments

3

Ok.. So if i'm not wrong this is the class you are using https://github.com/BijeshNair/NIDropDown/blob/master/NIDropDown.m

if you see this method

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

// Before you do hiding of the table just pass the indexPath as a tag to the button.
btnSender.tag = indexPath.row;
[self hideDropDown:btnSender];
}

So when you -rel is called you can use the button tag to open a new view controller in

-(void)rel{
   // use button tag to open respective view controller here.
  dropDown = nil;
}

Comments

2

By doing some modification in code you can do this

In NIDropDown.h add this code

@property (nonatomic, retain) NSString * str;

In NIDropDown.m add this code

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self hideDropDown:btnSender];

    UITableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];
    [btnSender setTitle:c.textLabel.text forState:UIControlStateNormal];

    NSLog(@"%@",c.textLabel.text);

    self.str = c.textLabel.text;   //here we are setting our str variable for later use

    for (UIView *subview in btnSender.subviews) {
        if ([subview isKindOfClass:[UIImageView class]]) {
            [subview removeFromSuperview];
        }
    }
    imgView.image = c.imageView.image;
    imgView = [[UIImageView alloc] initWithImage:c.imageView.image];
    imgView.frame = CGRectMake(5, 5, 25, 25);
    [btnSender addSubview:imgView];
    [self myDelegate];
}

In NIViewController.m add this code

- (void) niDropDownDelegateMethod: (NIDropDown *) sender {
    if ([sender.str isEqualToString:@"Hello0"]){
        //Put hello0VC transition code
        NSLog(@"dilip hello0");
    }else if ([sender.str isEqualToString:@"Hello1"]) {
        //Put hello1VC transition code
        NSLog(@"dilip hello1");
    }else if ([sender.str isEqualToString:@"Hello2"]){
        //Put hello2VC transition code
        NSLog(@"dilip hello2");
    }else if ([sender.str isEqualToString:@"Hello3"]){
        //Put hello3VC transition code
        NSLog(@"dilip hello3");
    }else if ([sender.str isEqualToString:@"Hello4"]){
        //Put hello4VC transition code
        NSLog(@"dilip hello4");
    }
    [self rel];
}

Comments

2

For that you can make custom PickerView and in that you can get this kind of view as You want.

And you have to implement pickerView's Delegate Method:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
      inComponent:(NSInteger)component
{
  if (row==0)
    {
        Hello1VC *VC1=[[Hello1VC alloc]initWithNibName:@"Hello1VC" bundle:nil];
        [self presentModalViewController:VC1 animated:YES];
    }
}

likeWise you can check index and based on that you can display ViewController

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.