gpt4 book ai didi

ios - 构建项目时声明的接口(interface)错误

转载 作者:行者123 更新时间:2023-11-29 04:24:10 25 4
gpt4 key购买 nike

我对 ios 开发相当陌生,按照“开始 ios5 开发”一书第 4 章的教程练习,我的代码遇到了一些编译错误。

这是我的 header 代码 .h 文件的样子

   #import <UIKit/UIKit.h>

@interface BIDViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITextField *namefIELD;

@property (strong, nonatomic) IBOutlet UITextField *numberField;
@property (strong, nonatomic) IBOutlet UILabel *sliderLabel;
@property (strong, nonatomic) IBOutlet UISegmentedControl *leftSwitch;
@property (strong, nonatomic) IBOutlet UISegmentedControl *rightSwitch;
@property (strong, nonatomic) IBOutlet UIButton *doSomethingButton;

-(IBAction)textFieldDoneEditing:(id)sender;
//to initialize the 'done' button when editing to confirm you have finished editing/

-(IBAction) backgroundTap:(id)sender;
- (IBAction)sliderChanged:(id)sender;
- (IBAction)switchChanged:(id)sender;
- (IBAction)toggleControls:(id)sender;
- (IBAction)buttonPressed:(id)sender;
@end

这是我的 .m 代码,我面临错误“'UISegmentedControl' 没有可见的 @interface 声明选择器 'setOn:animated;'

  @synthesize leftSwitch;
@synthesize rightSwitch;


- (IBAction)switchChanged:(id)sender {
UISwitch *whichSwitch = (UISwitch *)sender;
BOOL setting = whichSwitch.isOn;
[leftSwitch setOn: setting animated: YES]; //the error lies here/
[rightSwitch setO: setting animated: YES]; //the error lies here/
}

- (IBAction)toggleControls:(id)sender {
}

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

错误语句是“‘UISegmentedControl’没有可见的@interface声明选择器‘setOn:animated;’

请帮忙,我们将非常感激并投票:)

@PhilipMills ...这就是我所说的,只要我单击分段控制对象的左侧或右侧,就会在我的委托(delegate) header 代码上自动创建一个断点

 #import <UIKit/UIKit.h>

#import "BIDAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([BIDAppDelegate class])); //the breakpoint appears here.
}
}

最佳答案

UISwitch 有一个 setOn:animated: 方法,但 UISegmentedControl 没有。我猜测您分配给 leftSwitchrightSwitch 的对象不是您想要的类型(或教程想要的类型)。

关于ios - 构建项目时声明的接口(interface)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12600181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com