I'm pretty new to programming. I am creating a very simple iOS Quiz app just for practice. Here is what I have gotten done thus far:
The only problem I am having is getting the view controller to retrieve data from the dataModel file. I have read that I should probably be using Delegation, but I am just looking to know how to do it more simply...I ready something about the view controller and the data model file should have references to each other? If so, what would the coding look like?
Here is my coding thus far:
#import <UIKit/UIKit.h>
@interface onMyOwnViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *stateField;
@property (weak, nonatomic) IBOutlet UILabel *answerField;
- (IBAction)answerButton:(id)sender;
- (IBAction)stateButton:(id)sender;
@end
#import "onMyOwnViewController.h"
#import "dataModel.h"
@implementation onMyOwnViewController
- (IBAction)stateButton:(id)sender
{
NSString *myState = [stateArray objectAtIndex:0]; //this line produces an error.
[_stateField setText:myState];
[_answerField setText:@"hi"];
}
- (IBAction)answerButton:(id)sender
{
}
@end
Below is my dataModel coding:
#import <Foundation/Foundation.h>
@interface dataModel : NSObject
@property(nonatomic, strong) NSMutableArray *answerArray;
@property(nonatomic, strong) NSMutableArray *stateArray;
@end
#import "dataModel.h"
#import "onMyOwnViewController.h"
@implementation dataModel
- (id)init
{
self = [super init];
if(self){
_answerArray = [[NSMutableArray alloc]initWithObjects:@"Michigan", @"Illinios", nil];
_stateArray = [[NSMutableArray alloc]initWithObjects:@"Lansing", @"Springfield",
nil];
}
return self;
}
@end
When I run the app, everything works except retrieving data from the data model. When you replay, please reply with coding.