I'll just create a list of children and their information in table.This data are going to register before to receive this information from the sever. How can create a database in this app.?
Here are the codes ChildListViewController.m
#import "ChildListViewController.h"
#import "AppDelegate.h"
#import "Child.h"
#import "ChildDetailViewController.h"
@interface ChildListViewController ()
{
NSArray *_child_info;
}
@end
@implementation ChildListViewController
- (IBAction)unwindchild:(UIStoryboardSegue *)segue
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self dismissViewControllerAnimated:YES completion:nil];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_child_info = [[NSArray alloc] initWithObjects:appDelegate, nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"ChildListUpdate"
object:nil];
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:@"BusTrackingParentApp.sql"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TableIdentifier";
AppDelegate *appDelegate = [_child_info objectAtIndex:indexPath.row];
Child *cell = (Child *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Child" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[self.dbManager.arrColumnNames indexOfObject:appDelegate.name];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.beacon_id];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.status];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.longitude];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.latitude];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.server_created_date];
[self.dbManager.arrColumnNames indexOfObject:appDelegate.image];
cell.childName.text = appDelegate.name;
cell.childbeaconID.text = appDelegate.beacon_id;
cell.childstatus.text = appDelegate.status;
cell.childLoclong.text = appDelegate.longitude;
cell.childLoclat.text = appDelegate.latitude;
cell.serverCreatedDate.text = appDelegate.server_created_date;
cell.childimageview.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:appDelegate.image]]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 119;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.name != nil)
{
[self performSegueWithIdentifier:(@"a") sender:(self)];
}
else
{
NSLog(@"No Data %@", appDelegate.name);
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier]isEqualToString:@"a"])
{
ChildDetailViewController *vc = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
vc.appDelagate = [_child_info objectAtIndex:indexPath.row];
}
}
- (void) receiveTestNotification:(NSNotification *) notification
{
if ([[notification name] isEqualToString:@"ChildListUpdate"])
{
[self.tableView reloadData];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Aucun commentaire:
Enregistrer un commentaire