Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么不是';我的IBAction没有开火吗?_Ios_Ibaction - Fatal编程技术网

Ios 为什么不是';我的IBAction没有开火吗?

Ios 为什么不是';我的IBAction没有开火吗?,ios,ibaction,Ios,Ibaction,我有一个自定义类(FFFuelQuantityPickerVC)情节提要视图控制器,它包含一个UIPickerView和一个UIButton。UIButton连接到FFFuelQuantityPickerVC中名为fullButtonPressed的iAction。当使用故事板popover segue显示此视图控制器时,当UIButton“在内部触动”时,将触发fullButtonPressed iAction 但是,当我以编程方式初始化并在弹出窗口中显示FFFuelQuantityPicke

我有一个自定义类(FFFuelQuantityPickerVC)情节提要视图控制器,它包含一个UIPickerView和一个UIButton。UIButton连接到FFFuelQuantityPickerVC中名为fullButtonPressed的iAction。当使用故事板popover segue显示此视图控制器时,当UIButton“在内部触动”时,将触发fullButtonPressed iAction

但是,当我以编程方式初始化并在弹出窗口中显示FFFuelQuantityPickerVC时,按下UIButton不会触发iAction。为什么会这样?以下是在按下UITableViewCell中的按钮时执行编程演示的代码。(self.poc是一个可重用的popover控制器):

以下是FFFuelQuantityPickerVC:

//  FFFuelQuantityPickerVC.h
#import <UIKit/UIKit.h>

@protocol fuelPickerDelegate <NSObject>
-(void) fuelQuantityChangedL:(NSInteger) quantityL R:(NSInteger)quantityR;
@end

@interface FFFuelQuantityPickerVC : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *thisPicker;
@property (nonatomic) NSString *fuelQuantityL;
@property (nonatomic) NSString *fuelQuantityR;

@property (nonatomic) id delegate;

- (IBAction)fullButtonPressed;  //this is wired to the button 

@end

//
//  FFFuelQuantityPickerVC.m
#import "FFFuelQuantityPickerVC.h"

#define FUEL_MIN 0
#define FUEL_MAX 146
#define LEFT_COMPONENT 0
#define RIGHT_COMPONENT 1

@interface FFFuelQuantityPickerVC ()

@end

@implementation FFFuelQuantityPickerVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (!self.fuelQuantityL){
    self.fuelQuantityL = [NSString stringWithFormat:@"%i", FUEL_MAX];
    }
    if (!self.fuelQuantityR){
        self.fuelQuantityR = [NSString stringWithFormat:@"%i", FUEL_MAX];
    }
}

//set selected row to current values, if any
- (void) viewDidAppear:(BOOL)animated {
        [self.thisPicker selectRow:FUEL_MAX - [self.fuelQuantityL intValue] inComponent:LEFT_COMPONENT animated:YES];
        [self.thisPicker selectRow:FUEL_MAX - [self.fuelQuantityR intValue] inComponent:RIGHT_COMPONENT animated:YES];

}

//this method does not get called when the button is pressed (except when the VC is presented via storyboard popover segue)
- (IBAction)fullButtonPressed { 
    self.fuelQuantityL = [NSString stringWithFormat:@"%i", FUEL_MAX];
    self.fuelQuantityR = [NSString stringWithFormat:@"%i", FUEL_MAX];
    [self.thisPicker selectRow:0 inComponent:0 animated:YES];
    [self.thisPicker selectRow:0 inComponent:1 animated:YES];
    [self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
                                      R:[self.fuelQuantityR integerValue]];

}

#pragma mark - PickerViewDataSource delegate methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return (FUEL_MAX-FUEL_MIN + 1);
}

#pragma mark - PickerView delegate methods

 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
     float myWidth = self.view.frame.size.width;
 if (component == 0) return myWidth / 3;
 return (myWidth * 2 / 3);
 }

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    //TODO
    return 28;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%d", (FUEL_MAX)-row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == LEFT_COMPONENT){
        self.fuelQuantityL = [NSString stringWithFormat:@"%i", FUEL_MAX - row];
    } else {
        self.fuelQuantityR = [NSString stringWithFormat:@"%i", FUEL_MAX - row];
    }
    [self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
                                      R:[self.fuelQuantityR integerValue]];
}


@end
//FFFuelQuantityPickerVC.h
#进口
@协议选择器delegate
-(无效)燃料数量更改DL:(NSInteger)数量L R:(NSInteger)数量R;
@结束
@接口FFFuelQuantityPickerVC:UIViewController
@属性(弱、非原子)IBUIPickerView*此选择器;
@属性(非原子)NSString*fuelQuantityL;
@属性(非原子)NSString*fuelQuantityR;
@属性(非原子)id委托;
-(iAction)按下完整按钮//这是连接到按钮上的
@结束
//
//FFFuelQuantityPickerVC.m
#导入“FFFuelQuantityPickerVC.h”
#定义燃油最小值0
#定义最大燃油消耗量146
#定义左\u组件0
#定义组件1的右键
@接口FFFuelQuantityPickerVC()
@结束
@FFFuelQuantityPickerVC的实现
-(无效)viewDidLoad
{
[超级视图下载];
如果(!self.fuelQuantityL){
self.fuelQuantityL=[NSString stringWithFormat:@“%i”,FUEL_MAX];
}
如果(!self.fuelQuantityR){
self.fuelQuantityR=[NSString stringWithFormat:@“%i”,FUEL_MAX];
}
}
//将选定行设置为当前值(如果有)
-(无效)视图显示:(BOOL)动画{
[self.thisPicker selectRow:FUEL_MAX-[self.fuelQuantityL intValue]未组件:左组件动画:是];
[self.thisPicker selectRow:FUEL_MAX-[self.fuelQuantityR intValue]未组件:右侧未设置组件动画:是];
}
//按下按钮时不会调用此方法(除非VC通过情节提要popover segue显示)
-(iAction)FullButton按下{
self.fuelQuantityL=[NSString stringWithFormat:@“%i”,FUEL_MAX];
self.fuelQuantityR=[NSString stringWithFormat:@“%i”,FUEL_MAX];
[self.thisPicker selectRow:0不完整:0动画:是];
[self.thisPicker selectRow:0不完整:1动画:是];
[self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
R:[self.fuelQuantityR integerValue]];
}
#pragma标记-PickerViewDataSource委托方法
-(NSInteger)pickerView中组件的编号:(UIPickerView*)pickerView{
返回2;
}
-(NSInteger)pickerView:(UIPickerView*)pickerView行数组件:(NSInteger)组件{
返回(燃油最大值-燃油最小值+1);
}
#pragma标记-PickerView委托方法
-(CGFloat)pickerView:(UIPickerView*)元件的pickerView宽度:(NSInteger)元件{
float myWidth=self.view.frame.size.width;
如果(组件==0)返回myWidth/3;
返回(myWidth*2/3);
}
-(CGFloat)pickerView:(UIPickerView*)pickerView rowHeightForComponent:(NSInteger)component{
//待办事项
返回28;
}
-(NSString*)pickerView:(UIPickerView*)pickerView标题箭头:(NSInteger)组件行:(NSInteger)组件{
返回[NSString stringWithFormat:@“%d”(燃料最大值)-行];
}
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row不完整项:(NSInteger)组件{
如果(组件==左组件){
self.fuelQuantityL=[NSString stringWithFormat:@“%i”,FUEL_MAX-row];
}否则{
self.fuelQuantityR=[NSString stringWithFormat:@“%i”,FUEL_MAX-row];
}
[self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
R:[self.fuelQuantityR integerValue]];
}
@结束

这是我的代码。当我单击单元格并从UIPickerView中选取值以在我的UITableviewCell中显示UILabel中的值时,我使用此代码显示UIPopoverController

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 1)
        {
            //PopoverView controller.........................................................................
            UIViewController *popoverViewController = [[UIViewController alloc] init];

            //PopoverView....................................................................................
            UIView *popoverView = [[UIView alloc]init];
            [popoverView setBackgroundColor:[UIColor blackColor]];

            //Navigation bar and Barbutton items..............................................................
            UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
            navBar.barStyle = UIBarStyleBlackTranslucent;

            UIBarButtonItem *btnDone = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doDone)];
            UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(doCancel)];

            UINavigationItem *navItem = [[UINavigationItem alloc]init];
            navItem.rightBarButtonItem = btnDone;
            navItem.leftBarButtonItem = btnCancel;

            navBar.items = [[NSArray alloc]initWithObjects:navItem, nil];
            [popoverView addSubview:navBar];

            //UIPickerView.....................................................................................
            UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 180)];
            popoverViewController.contentSizeForViewInPopover = CGSizeMake(320, 230);
            sortPickerView.delegate = self;
            sortPickerView.dataSource = self;
            sortPickerView.showsSelectionIndicator = YES;
            [popoverView addSubview:sortPickerView];
            NSUserDefaults *ud1 = [NSUserDefaults standardUserDefaults];

            if ([ud1 objectForKey:@"languages"]) 
            {
                NSUInteger row1 = [languages indexOfObject:[ud1 objectForKey:@"languages"]];
                if (row1) 
                {
                    [sortPickerView selectRow:row1 inComponent:0 animated:YES];
                }   
            }
            else
            {
                [sortPickerView selectRow:0 inComponent:0 animated:YES]; 
            }

            CGRect popFrame = lbl_language.frame;
            popFrame.origin.y = popFrame.origin.y + popFrame.size.height + 70;
            popFrame.origin.x = popFrame.origin.x + 100;
            popoverViewController.view = popoverView;
            self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
            [self.SortPopover presentPopoverFromRect:popFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        }
    }

由于我不清楚的原因,UI按钮没有收到按钮-它从未突出显示。它没有被我能看到的另一个视图覆盖(唯一的另一个视图是选择器)。无论如何,我添加了一个UIToolbar,并将按钮更改为bar按钮项,效果很好

在这里,你可以触发你的按钮动作。。只需将代码放在触发按钮操作的位置。单击单元格时需要UIPopoverController。。我是对的。我不确定我是否明白你的意思。IBAction方法位于FFFuelQuantityPickerVC视图控制器中。self.poc是一个UIPopoverController,通过更改其contentViewController重新使用。我的ViewController的picker部分工作正常-委托方法pickerView:didSelectRow:Incomonent:正在按预期调用。这是连接到ViewController视图中“我的UIButton”的iAction方法未被触发。请将,放置在触发按钮的位置。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 1)
        {
            //PopoverView controller.........................................................................
            UIViewController *popoverViewController = [[UIViewController alloc] init];

            //PopoverView....................................................................................
            UIView *popoverView = [[UIView alloc]init];
            [popoverView setBackgroundColor:[UIColor blackColor]];

            //Navigation bar and Barbutton items..............................................................
            UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
            navBar.barStyle = UIBarStyleBlackTranslucent;

            UIBarButtonItem *btnDone = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doDone)];
            UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(doCancel)];

            UINavigationItem *navItem = [[UINavigationItem alloc]init];
            navItem.rightBarButtonItem = btnDone;
            navItem.leftBarButtonItem = btnCancel;

            navBar.items = [[NSArray alloc]initWithObjects:navItem, nil];
            [popoverView addSubview:navBar];

            //UIPickerView.....................................................................................
            UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 180)];
            popoverViewController.contentSizeForViewInPopover = CGSizeMake(320, 230);
            sortPickerView.delegate = self;
            sortPickerView.dataSource = self;
            sortPickerView.showsSelectionIndicator = YES;
            [popoverView addSubview:sortPickerView];
            NSUserDefaults *ud1 = [NSUserDefaults standardUserDefaults];

            if ([ud1 objectForKey:@"languages"]) 
            {
                NSUInteger row1 = [languages indexOfObject:[ud1 objectForKey:@"languages"]];
                if (row1) 
                {
                    [sortPickerView selectRow:row1 inComponent:0 animated:YES];
                }   
            }
            else
            {
                [sortPickerView selectRow:0 inComponent:0 animated:YES]; 
            }

            CGRect popFrame = lbl_language.frame;
            popFrame.origin.y = popFrame.origin.y + popFrame.size.height + 70;
            popFrame.origin.x = popFrame.origin.x + 100;
            popoverViewController.view = popoverView;
            self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
            [self.SortPopover presentPopoverFromRect:popFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        }
    }