How to fire uibarbuttonitem click event programmatically

后端 未结 8 2314
旧时难觅i
旧时难觅i 2020-12-05 05:41

I have created a UIActionSheet

UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@\"\"
                                                       


        
8条回答
  •  抹茶落季
    2020-12-05 05:47

    Well this is how I use actionSheet ..

    actionSheet  = [[UIActionSheet alloc] initWithTitle:nil 
                                                                 delegate:nil
                                                        cancelButtonTitle:nil
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:nil];
    
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
    
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;
    
    [actionSheet addSubview:pickerView];
    [pickerView release];
    
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];
    [closeButton release];
    
    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
    
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
    

    Once you are done with this just define a selector in your .m like..

    -(void)dismissActionSheet{
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 
    }
    

    so inside dismiss action sheet you can re-write what is happening inside bar button item... hope this helps.

提交回复
热议问题