iOS - 删除我删除的属性的引用

时间:2014-02-09 03:26:49

标签: ios iphone objective-c xcode

我之前创建了一个按钮IBAction,并将其命名为“hi”。我从 .h .m 文件中手动删除了代码,并从故事板中删除了该按钮,现在我收到以下错误:

  

2014-02-08 18:31:53.135 MadLibs2 [7645:70b] * 终止应用程序   未捕获的异常'NSUnknownKeyException',原因:   '[setValue:forUndefinedKey:]:这个类   密钥符号不符合密码值。

如何删除'hi'参考?

//  JBViewController.h
//  MadLibs2

#import <UIKit/UIKit.h>

@interface JBViewController : UIViewController

// Properties manage an object's internal data
//// A properties data is stored in an instance variable or ivar (e.g., *sliderLabel)
// The property accesses ivars via getter/setter methods (aka accessors)
// put @property in front of the declaration of the ivar
// We access properties using the self keyword
@property (weak, nonatomic) IBOutlet UILabel *sliderLabel;
- (IBAction)sliderChanged:(id)sender;
- (IBAction)toggleShowHide:(id)sender;

@property (weak, nonatomic) IBOutlet UIView *settingsView;

@property (weak, nonatomic) IBOutlet UISwitch *endingSwitch;

@property (weak, nonatomic) IBOutlet UILabel *petsLabel;

@property (weak, nonatomic) IBOutlet UIStepper *petsStepper;

- (IBAction)stepperChanged:(id)sender;

- (IBAction)createStory:(id)sender;
@end

//  JBViewController.m
//  MadLibs2

#import "JBViewController.h"

@interface JBViewController ()

@end

@implementation JBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sliderChanged:(id)sender {
    UISlider *slider = (UISlider *)sender;
    //why not NSInteger?
    int numberAsInt = (int) (slider.value + 0.5f);
    NSString *newText = [[NSString alloc] initWithFormat:@"%d", numberAsInt];
    //self is used to access properties
    /// What is 'text' used for? Is it a method?
    self.sliderLabel.text = newText;
}

- (IBAction)toggleShowHide:(id)sender {
    UISegmentedControl *segmentedControl =
    (UISegmentedControl *)sender;
    NSInteger segment = segmentedControl.selectedSegmentIndex;
    if (segment == 0)
        // self is used to access properties
        [self.settingsView setHidden:YES];
    else
        [self.settingsView setHidden:NO];

}
- (IBAction)stepperChanged:(id)sender {
    // update petsLabel to increase or decrease value
    UIStepper *stepper = (UIStepper *) sender;
    //NSLog([NSString stringWithFormat:@"%d",(int)stepper.value]);
    int stepperNum = (int)stepper.value;
    NSString *numPets = [[NSString alloc] initWithFormat:@"%d", stepperNum];
    self.petsLabel.text = numPets;
}

- (IBAction)createStory:(id)sender {
}
@end

3 个答案:

答案 0 :(得分:1)

仅当您从 .h 文件中删除IBOutlet但在故事板中没有删除时才会发生这种情况。

如果您在运行程序时仍然可以看到IBOutlet,则可能是您没有从故事板中删除它。

也许您的某些IBOutlet没有标题,文字或颜色,并且您认为已删除它们,但它们(或其中一个,导致问题)仍然存在。< / p>

添加屏幕截图:

例如:

我这里有一个分段控件和一个按钮,因为它没有标题,文字和背景颜色所以不可见:

enter image description here

但按钮实际上仍然是,当我通过将鼠标光标从左上角拖动到右下角来突出显示它时可以证明:

enter image description here

如果我在认为我删除它(以及 .h 中的连接和操作)时意外点击它,我会收到错误。

答案 1 :(得分:0)

右键单击故事板中的UIButton - 您将看到当前设置的所有操作的列表。点击靠近“hi”操作的小“x”并将其删除。

答案 2 :(得分:0)

您应该选择按钮并查看“连接检查器”,引用应该出现在那里。