自定义函数中 UI 字段的未声明标识符



我创建了一个如下所示的自定义函数,其中包含从 .m 文件中的按钮单击事件复制的代码。 代码工作正常,直到我将其复制到我的 displayDev 函数中。 此代码中的最后三行给了我一个"使用未声明的标识符"错误。 有人可以帮我弄清楚为什么fullVerseLabel.text,VerseField.text和InterpretField.text都显示为未声明的标识符吗? 下面是我的 .h 代码,我在其中声明了这些 UI 字段。

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

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;
}

你用以下命令开始了这个方法:

void displayDev (NSInteger dayNum)

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

- (void)displayDev:(NSInteger)dayNum

最新更新