【问题标题】:Undeclared - 'first use in function'未声明 - '第一次在函数中使用'
【发布时间】:2011-09-19 07:38:03
【问题描述】:

我是 Objective-C 的新手,虽然我对 Android 有很好的了解。我正在尝试调用一个方法,但它让我“第一次在函数中使用”。我知道我犯了一个愚蠢的错误,但专家们可以很容易地找出答案。

RootViewController.h

#import <UIKit/UIKit.h>
#import "ContentViewController.h"

@interface RootViewController : UITableViewController {
    ContentViewController *contentViewController;
}

@property (nonatomic, retain) ContentViewController *contentViewController;

- (NSString*)getContentFileName:(NSString*)title; //<--- This function declartion

@end

RootViewController.m

#import "RootViewController.h"
#import "HAWATAppDelegate.h"
#import "ContentViewController.h"

@implementation RootViewController
@synthesize contentViewController;

...
more methods
...

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    HAWATAppDelegate *appDelegate = (HAWATAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *title = (NSString *) [appDelegate.titles objectAtIndex:indexPath.row];

    NSString *fileName = getContentFileName:title; //<--- Here is the error

    ...
}

- (NSString*) getContentFileName:(NSString*)title {
    return [title lowercaseString];
}

@end

我一定缺少一件简单的事情。请告诉我。提前致谢。

【问题讨论】:

    标签: iphone objective-c ios function methods


    【解决方案1】:

    您调用的方法错误。 Objective-C 中调用方法的格式为:

    [object selectorWithArgument:foo bar:baz];
    

    所以出现错误的那一行应该是:

    NSString *fileName = [self getContentFileName:title]; //<--- Here is the error
    

    【讨论】:

      【解决方案2】:

      OMG!! 那应该是[self getContentFileName:title];

      【讨论】:

      • 哇!谢谢@EmptyStack。现在工作。将在 12 分钟内接受您的回答;)
      • OOOOMMMMGGGG,优胜者鸡晚餐。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 2014-04-22
      • 2012-05-07
      • 2012-07-13
      • 2013-05-19
      • 1970-01-01
      相关资源
      最近更新 更多