0

我使用从 .m 文件中的按钮单击事件中复制的代码创建了一个自定义函数,如下所示。代码运行良好,直到我将它复制到我的 displayDev 函数中。这段代码的最后三行给了我一个“使用未声明的标识符”错误。有人能帮我弄清楚为什么 fullVerseLabel.text、VerseField.text 和 InterpretationField.text 都显示为未声明的标识符吗?下面也是我声明这些 UI 字段的 .h 代码。

您可以提供的任何帮助将不胜感激。非常感谢!

void displayDev (NSInteger dayNum)
{   NSString *plistFile = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plistFile];

    NSString *bookString = [[dict objectForKey:[NSString stringWithFormat:@"Day %d", dayNum]] objectForKey:@"Book"];
    NSString *chapterString = [[dict objectForKey:[NSString stringWithFormat:@"Day %d", dayNum]] objectForKey:@"Chapter#"];
    NSString *verseString = [[dict objectForKey:[NSString stringWithFormat:@"Day %d", dayNum]] objectForKey:@"Verse#"];

    NSString *fullVerseString = [bookString stringByAppendingString:@" "];
    fullVerseString = [fullVerseString stringByAppendingString:chapterString];
    fullVerseString = [fullVerseString stringByAppendingString:@":"];
    fullVerseString = [fullVerseString stringByAppendingString:verseString];
    fullVerseLabel.text = fullVerseString;
    VerseField.text = [dict objectForKey:[NSString stringWithFormat:@"Day %d", dayNum]objectForKey:@"Verse"];
    InterpretationField.text = [dict objectForKey:[NSString stringWithFormat:@"Day %d", dayNum] objectForKey:@"Interpretation"];

    currentlyViewing = dayNum;
}

我在我的 .h 文件中声明了变量并链接到我的故事板。

@interface FirstViewController : UIViewController
{   IBOutlet UILabel *fullVerseLabel;
    IBOutlet UITextView *VerseField;
    IBOutlet UITextView *InterpretationField;
    IBOutlet UITextField *TextField;
}
4

1 回答 1

1

您开始使用此方法:

void displayDev (NSInteger dayNum)

使用该语法,您实际上将其声明为 C 函数,而不是 Objective-C。您无法在 C 函数中访问您的插座或其他实例变量。您可以通过将第一行更改为:

- (void)displayDev:(NSInteger)dayNum
于 2012-06-25T18:54:08.033 回答