Objective c 缺少方法声明的上下文?
我正在尝试创建一个应用程序,当我添加这个iAction时,它给了我一个错误:缺少方法声明的上下文。我已经查阅了如何解决这个问题,但我有点困惑,因为我是一个初学者。错误出现在my.m文件中:Objective c 缺少方法声明的上下文?,objective-c,Objective C,我正在尝试创建一个应用程序,当我添加这个iAction时,它给了我一个错误:缺少方法声明的上下文。我已经查阅了如何解决这个问题,但我有点困惑,因为我是一个初学者。错误出现在my.m文件中: #import "QRscannerSecondViewController.h" @end @interface QRscannerSecondViewController () @end @implementation QRscannerSecondViewController - (id)in
#import "QRscannerSecondViewController.h"
@end
@interface QRscannerSecondViewController ()
@end
@implementation QRscannerSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Info", @"Info");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
- (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.
}
@end
-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}
但我认为如果我也包括我的.h文件,那会有所帮助
#import <UIKit/UIKit.h>
@interface QRscannerSecondViewController : UIViewController
@end
@interface TextGameViewController : UIViewController
{
IBOutlet UITextField *input;
IBOutlet UILabel *line11;
NSString *l11;
}
-(IBAction)button1;
#导入
@接口QRscannerSecondViewController:UIViewController
@结束
@界面文本GameViewController:UIViewController
{
IBOutlet UITextField*输入;
IBUILabel*第11行;
NSString*l11;
}
-(iAction)按钮1;
您需要输入以下代码:
-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}
在
@end
之前,您不会将方法的实现置于@implementation
范围之外,您最好使用标准的-(IBActon)按钮:(id)sender代码>方案。