0

クラスのメソッドformatSearchStringを作成しましたが、それを実装する前に行で呼び出そうとしています (関係ありませんか?)。次のエラーが表示されます。

Error: Semantic Issue
Use of undeclared identifier 'formatSearchString'

XCode 4.6.2 を使用しています

インターフェイス ファイルFHViewController.h:

#import <Foundation/Foundation.h>

@interface FHViewController : UITableViewController
<UITableViewDataSource, UITableViewDelegate, NSURLConnectionDataDelegate>
@property(strong, nonatomic) NSString *searchTerm;
- (NSString *)formatSearchString:(NSString *)userEntry;
@end

実装ファイルFHViewController.m:

#import "FHViewController.h"

@interface FHViewController()
- (NSString *)formatSearchString:(NSString *)userEntry;
@end

@implementation FHViewController
@synthesize searchTerm;

-(void)viewDidLoad
{
     [super viewDidLoad];
     NSString *formatted = [formatSearchString userEntry:searchTerm];
}

- (NSString *)formatSearchString:(NSString *)userEntry
{
     NSLog(@"User Entry: %@", userEntry);
     return @"Dummy string for now";
}
@end
4

3 に答える 3

4
NSString *formatted = [formatSearchString userEntry:searchTerm];

その行は間違っています。違いに注意してください:

NSString *formatted = [self formatSearchString:searchTerm];
于 2013-04-27T20:32:01.927 に答える
0

メソッド名ではなく変数名として formatSearchString を使用しています。オブジェクトで formatSearchString を呼び出す必要があります。

NSString *formattedString = [self formatSearchString:mySearchString];
于 2013-04-27T20:31:54.440 に答える
0

Objective C でのメソッド呼び出しの構文は次のとおりです[receiver method: param1 ...]。したがって、コードを次のように変更する必要があります。

-(void)viewDidLoad
{
    [super viewDidLoad];
    NSString *formatted = [self formatSearchString: searchTerm];
}
于 2013-04-27T20:32:21.910 に答える