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

标签 objective-c

我正在尝试创建一个应用程序,当我添加这个 IBAction 时,它给了我错误 Missing context for method declaration。我已经查过如何解决这个问题,但由于我是初学者,所以我有点困惑。错误出现在我的 .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;

最佳答案

你需要把代码:

-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}

@end之前。

关于objective-c - 缺少方法声明的上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14667832/

相关文章:

ios - 对从核心数据中获取的对象进行变音符号敏感排序?

ios - 在 objective-c 中的方法之间传递值

ios - JSON 对象为具有值的键返回空字符串

objective-c - 如何更改 Xcode 项目中的默认 MainMenu.xib 文件?

c - 在 Objective-C/iPhone 应用程序中使用 "classic"malloc()/free() 可以吗?

objective-c - 在 Objective-C 中使用 C 风格数组

iphone - [string UTF8String] 的正确内存管理

ios - 如何在 UICollectionView 中设置 UICollectionViewCell 的垂直顶部对齐方式。 ( Objective-C )

ios - 表格单元格中的动画约束更改

iphone - 创建UITableView后调用哪个协议(protocol)方法