我正在尝试创建一个应用程序,当我添加这个IBAction时,它给了我错误方法声明的上下文。我已经查找了如何解决这个问题,但由于我是初学者,我有点困惑。错误出现在我的.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;
答案 0 :(得分:4)
您需要输入代码:
-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}
在@end
。