Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Objective c 缺少方法声明的上下文?_Objective C - Fatal编程技术网

Objective c 缺少方法声明的上下文?

Objective c 缺少方法声明的上下文?,objective-c,Objective C,我正在尝试创建一个应用程序,当我添加这个iAction时,它给了我一个错误:缺少方法声明的上下文。我已经查阅了如何解决这个问题,但我有点困惑,因为我是一个初学者。错误出现在my.m文件中: #import "QRscannerSecondViewController.h" @end @interface QRscannerSecondViewController () @end @implementation QRscannerSecondViewController - (id)in

我正在尝试创建一个应用程序,当我添加这个iAction时,它给了我一个错误:缺少方法声明的上下文。我已经查阅了如何解决这个问题,但我有点困惑,因为我是一个初学者。错误出现在my.m文件中:

#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方案。