![](/img/trans.png)
[英]Errors: “Expected selector for Objective-C method” and “Expected method body” on #import <Foundation/Foundation.h>
[英]xcode Expected Selector for objective-c method and Missing @end errors
这是我的代码
#import "MasterViewController.h"
#import "DiseaseResultsViewController.h"
@interface MasterViewController ()
@end
@implementation MasterViewController
@synthesize symptomTextField;
- (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.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"searchFunctionSegue"])
{
if ([self.symptomTextField.text length])
{
DiseaseResultsViewController *resultsViewController = [segue destinationViewController];
resultsViewController.symptomSearchString = self.symptomTextField.text;
}
}
}
@end
我在“if([self.symptomTextField.text length]”行上得到“Objective-C方法的预期选择器”错误
并在“DiseaseResultsViewController * resultsViewController = [segue destinationViewController]”行下面的行中出现“expected method body”和“missing @end”错误
我已经检查了所有导入的文件正确的@end。
有任何想法吗?
在我的情况下,错误是在.h中报告的:
但问题出在.m:
有一个错字,我错误地输入+。
这是我见过的最令人沮丧和愚蠢的错误之一。 我只是剪切然后粘贴在代码中,错误消失了:S
我有同样的错误,我错误地在.m
文件中写了“+”符号。
在寻找代码半小时后,我remove "+"
符号,错误消失了。
我确信你太沮丧了,就像我一样。 在我的情况下,我从.h文件中删除了“@end”,这导致了错误。 再次添加它,错误消失。 别紧张。
在我的情况下,更多的是在方法声明中使用明显保留的关键字'connect'。 更改为' - (void)initConnect;' 为我解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.