Undeclared Identifier for UI fields in custom function
-
16-06-2021 - |
Pregunta
I created a custom function shown below with code I copied from a button click event in my .m file. The code worked fine until I copied it into my displayDev function. The last three lines in this code give me a "Use of undeclared identifier" error. Can someone help me figure out why fullVerseLabel.text, VerseField.text, and InterpretationField.text are all displaying as undeclared identifiers? Also below is my .h code where I declared these UI fields.
Any help you can provide will be greatly appreciated. Thanks so much!
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;
}
I have the variables declared in my .h file and linked to my storyboard.
@interface FirstViewController : UIViewController
{ IBOutlet UILabel *fullVerseLabel;
IBOutlet UITextView *VerseField;
IBOutlet UITextView *InterpretationField;
IBOutlet UITextField *TextField;
}
Solución
You started this method with:
void displayDev (NSInteger dayNum)
With that syntax, you're actually declaring this as a C function, not Objective-C. You're unable to access your outlets or other instance variables in a C function. You can change it to an Objective-C instance method by changing the first line to:
- (void)displayDev:(NSInteger)dayNum