[英]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.