Below is a simple example of how I'm reading from a plist and displaying the data in a table view. If I were to use a objects to represent my model, how would I be doing that?
@interface RootViewController : UITableViewController {
NSMutableArray *namesArray;
}
@property (nonatomic, retain) NSMutableArray *namesArray;
@end
@implementation RootViewController
@synthesize namesArray;
- (void)viewDidLoad{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"];
NSMutableArray *tempArray = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.namesArray = tempArray;
[tempArray release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [namesArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [namesArray objectAtIndex:indexPath.row];
return cell;
}
Can anyone show me the proper way of constructing my Model as per MVC pattern for the above scenario? I'm guessing I would be using a singleton to return a set of Name objects. I basically want to learn the correct manner of using Model objects to represent my data.