In my TableViewController, I set the data I want to load in my DetailView (ws)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sender:(id)sender{
detailViewController *detailVC = [[detailViewController alloc] init];
detailVC.ws = [self.tabAssociation objectAtIndex:indexPath.row];
[detailVC viewDidLoad] ;
//detailVC.descriptionTextView = [[UITextView alloc] init];
//[self.navigationController pushViewController:detailVC animated:YES];
}
And this is what my DetailView must load
- (void)viewDidLoad
{
[super viewDidLoad];
self.barre.title = self.ws.associationName ;
self.descriptionTextView.text = self.ws.associationDescription ;
}
But when I select the row, a white page appears and not my associationDescription in a text view, neither my associationName
But my viewDidLoad seems to be called before detailVC.ws is loaded, ie my detailVC is empty
Here is my TableViewController.h
import UIKit/UIKit.h
#interface MasterViewController : UITableViewController{
NSArray *tabAssociation;
}
#property (nonatomic, retain) NSArray *tabAssociation;
#end
And the TableViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController () {
}
#end
#implementation MasterViewController
#synthesize tabAssociation ;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *dictFromFile = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:#"AssociationTest" ofType:#"plist"]];
NSMutableArray *associationToAdd = [[NSMutableArray alloc] init];
NSEnumerator *enumerator = [dictFromFile objectEnumerator];
NSDictionary *anObject;
while ((anObject = [enumerator nextObject])) {
association *newAssocition = [[association alloc] initWithDictionaryFromPlist: anObject];
[associationToAdd addObject: newAssocition];
}
self.tabAssociation = [NSArray arrayWithArray:associationToAdd];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tabAssociation.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// On récupère l'objet Website qui correspon à la ligne que l'on souhaite afficher
association *ws = [self.tabAssociation objectAtIndex:indexPath.row];
cell.textLabel.text = ws.associationName;
// On renvoie la cellule configurée pour l'affichage
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sender:(id)sender{
detailViewController *detailVC = [[detailViewController alloc] init];
detailVC.ws = [self.tabAssociation objectAtIndex:indexPath.row];
//[detailVC viewDidLoad] ;
[self presentViewController:detailVC animated:YES completion:nil];
//detailVC.descriptionTextView = [[UITextView alloc] init];
//[self.navigationController pushViewController:detailVC animated:YES];
}
/*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}*/
#end
You should never call -viewDidLoad directly. What you want to do is present you detailViewController somehow.
If you're inside a UINavigationController, something like:
[self.navigationController pushViewController:detailVC animated:YES];
should work. If you're not, then you have to think about how you're going to present your view controller.
You can try something like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sender:(id)sender{
detailViewController *detailVC = [[detailViewController alloc] init];
detailVC.ws = [self.tabAssociation objectAtIndex:indexPath.row];
[self presentViewController: detailVC animated:YES completion:nil];
}
Related
I used the Master - Detail application to create a new project in xcode. Each time I run my program, the rows are not visible in the master view. Thanks in advance! Please check my code below...
MasterViewController.h
#import <UIKit/UIKit.h>
#class DetailViewController;
#interface MasterViewController : UITableViewController
#property (strong, nonatomic) DetailViewController *detailViewController;
#end
MasterViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController ()
#property NSMutableArray *objects;
#end
#implementation MasterViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] ***emphasized text***initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *) [[self.splitViewController.viewControllers lastObject] topViewController];
}
-(void)viewWillAppear:(BOOL)animated {
self.clearsSelectionOnViewWillAppear = self.splitViewController.isCollapsed;
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender {
if (!self.objects) {
self.objects = [[NSMutableArray alloc] init];
}
[self.objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = self.objects[indexPath.row];
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
[controller setDetailItem:object];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return self.objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSDate *object = self.objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
#end
DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController
#property (strong, nonatomic) id detailItem;
#property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#end
DetailViewController.m
#import "DetailViewController.h"
#interface DetailViewController ()
#end
#implementation DetailViewController
#pragma mark - Managing the detail item
-(void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
-(void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
-(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
-(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I figured, if you scale the size of the device to 75% and 100%, the rows will display. I guess this has something to do with xcode.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *second=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
second.getString=[getArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"Action" sender:nil]; }
How to pass data from one view to another,In my app there are some objects i want that when i tap on any cell then that value should be shown on next ViewController which having UILabel?
Create a init method in your SecondViewController as shown below.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withData:(NSString *) data {
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.data = data;
// write your own code here
}
return self;
}
In your tableview's didSelectRowAtIndexPath row method get the string and then push the controller as shown below
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSSting *stringData = #"hi";// get your data and passing to stringData
SecondViewController *secondVC=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil withData:stringData];
[self.navigationController pushViewController: secondVC animated:YES];
}
try this
create an instance variable NSString * sendingText ;// if you want to send text(string)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
sendingText = [getArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"Action" sender:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Action"]) // this check is optional if there is only on segue
{
SecondViewController *second= (SecondViewController *)segue.destinationViewController;
second.getString = sendingText;
}
}
in SecondViewController.h
#interface SecondViewController : UIViewController
{
UILabel * exampleLabel;
}
#property NSString * getString;
#end
and in SecondViewController.m
-(void)viewDidLoad
{
exampleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 100, 30)];
[self.view addSubview:exampleLabel];
}
-(void)viewWillAppear:(BOOL)animated
{
exampleLabel.text = getString;
}
I am new to Ios programming i want to display the data from master view controller into the detail view controller, i am using the master detail template from xcode. the detail array is working it shows the detail in label, how ever i want to display the title as well which is stored in _objects array,
here is my code
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController () {
NSMutableArray *_detailObjects;
NSMutableArray *_thumbnailImage;
}
#end
#implementation MasterViewController
#synthesize _objects;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title= #"Zodiac List";
_objects = [[NSMutableArray alloc] initWithObjects:
#"value 1",
#"value 2",
#"value 3",
#"value 4",
#"value 5",
,nil];
_detailObjects = [[NSMutableArray alloc] initWithObjects:
#"detail of value 1",
#"detail of value 2",
#"detail of value 3",
#"detail of value 4",
#"detail of value 5",
, nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSMutableArray *object = _detailObjects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
#end
the detail is working fine how ever i want to display the value 1, value 2,value 2 in a label as well..
here is my detail view controller code..
#property (strong, nonatomic) id detailItem;
#property (strong, nonatomic) id detailItemTitle;
#property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#property (weak, nonatomic) IBOutlet UILabel *zodiacNameLabel;
here is .m file code
#import "DetailViewController.h"
#import "MasterViewController.h"
#interface DetailViewController ()
- (void)configureView;
#end
#implementation DetailViewController
#synthesize zodiacNameLabel;
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
-(void) setDetailItemTitle:(id)detailItemTitle{
if (_detailItemTitle !=detailItemTitle) {
_detailItemTitle = detailItemTitle;
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
// self.zodiacNameLabel.text = [self.]
MasterViewController *master = [[MasterViewController alloc] init];
zodiacNameLabel.text = [master._objects objectAtIndex:0];
}
// if (self.detailItemTitle) {
// self.zodiacNameLabel.text = [self.detailItem description];
// }
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
// MasterViewController *master = [[MasterViewController alloc] init];
// zodiacNameLabel.text = [master._objects objectAtIndex:0];
// MasterViewController *master = [[MasterViewController alloc]init];
// zodiacNameLabel.text = [master._objects objectAtIndex:0]; // you can get first element of an array
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Implement delegate method of tableview which is in your masterviewcontroller and then inside that push your data whatever you want to display in masterviewcontroller like that:-
Assuming that below delegate is in your masterViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_yourController = [[yourController alloc] initWithNibName:#"yourController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:_yourController animated:YES];
}
Now this will alloc, initialize and load your nib into detailviewcontroller and if you want to send message from master to detail then declare property method in detailviewcontroller and just pass it from above like that below:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_yourDetailController = [[yourDetailController alloc] initWithNibName:#"yourDetailController" bundle:[NSBundle mainBundle]];
[_yourDetailController setTempString:#"test"]; //Assuming that tempString is declared in yourDetailController class
[self.navigationController pushViewController:_yourDetailController animated:YES];
}
Make an array that is "tmpArray" in detailViewController and then you can copied _objects array in to tmpArray. like this
MastrerViewController.m
DetailViewController *detail = [[DetailViewController alloc]init];
detail.tmpArray = [[NSMutableArray alloc] initWithArray:_objects];
DetailViewController.h
#property (nonatomic,retain) NSMutableArray *tmpArray;
I have an iphone app that I'm trying to make a universal app. I created a separate project to play around with creating a split view app for iPad. I got the basics of it working so I'm trying to implement it in my existing project but I'm getting an error when running on iPad.
2013-06-06 08:57:08.716 KFBNewsroom[26898:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "KFBMasterViewController" nib but didn't get a UITableView.'
The code for the split view is the same as it was in my test project so I can't figure out why it won't work here. Any ideas?
Here is the code from my didFinishLaunchingWithOptions method where I say what to load on different devices.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
self.window.rootViewController = self.tabBarController;
}
else
{
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
self.window.rootViewController = self.splitViewController;
}
MasterViewController.h:
#import <UIKit/UIKit.h>
#class KFBDetailViewController;
#interface KFBMasterViewController : UITableViewController
#property (strong, nonatomic) KFBDetailViewController *detailViewController;
#end
MasterViewController.m:
#import "KFBMasterViewController.h"
#import "KFBDetailViewController.h"
#import "DetailViewManager.h"
#interface KFBMasterViewController () {
NSMutableArray *_objects;
NSMutableArray *menu;
}
#end
#implementation KFBMasterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Master", #"Master");
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
// UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
// self.navigationItem.rightBarButtonItem = addButton;
menu = [NSMutableArray arrayWithObjects:#"Home", #"Public Affairs", #"Action Alerts", #"Market Updates", #"Ag Stories", #"KFB News", #"Member Benefits", #"Monthly Video", #"Photos", #"Social Media", #"About Us", #"Contact Us", #"KYFB.com", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return menu.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:#"CellImage.png"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// NSDate *object = _objects[indexPath.row];
// cell.textLabel.text = [object description];
cell.textLabel.text = [menu objectAtIndex:indexPath.row];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
cell.textLabel.font = [UIFont fontWithName:#"FranklinGothicStd-ExtraCond" size:20.0];
cell.textLabel.textColor = [UIColor whiteColor];
cell.backgroundView = image;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#end
You probably have to change the super-class of your rootViewController from UITableViewController to UIViewController.
Im new to IOS app programming - I went though the iOS second app tutorial (the bird sighting one) and I have 2 issues when I get to the end and any pointers would be most appreciated.
The + button on the main view has disappeared and I dont understand why? Which part of code governs this?
When selecting the pigeon bird in the main view, the detail view comes up but with detail still in all the items, so Bird Name is still detail, location is still detail etc.
Any help would be greatly appreciated.
Thanks
Edit - Added the .h and .m code for the masterviewcontroller
.h
#import <UIKit/UIKit.h>
#class BirdSightingDataController;
#interface BirdsMasterViewController : UITableViewController
#property (strong, nonatomic) BirdSightingDataController *dataController;
- (IBAction)done:(UIStoryboardSegue *)segue;
- (IBAction)cancel:(UIStoryboardSegue *)segue;
#end
.m
#import "BirdsMasterViewController.h"
#import "BirdsDetailViewController.h"
#import "BirdSightingDataController.h"
#import "BirdSighting.h"
#import "AddSightingViewController.h"
#implementation BirdsMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
self.dataController = [[BirdSightingDataController alloc] init];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem.accessibilityHint = #"Adds a new bird sighting event";
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.dataController countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"BirdSightingCell";
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
[[cell textLabel] setText:sightingAtIndex.name];
[[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
- (IBAction)done:(UIStoryboardSegue *)segue
{
if ([[segue identifier] isEqualToString:#"ReturnInput"]) {
AddSightingViewController *addController = [segue sourceViewController];
if (addController.birdSighting) {
[self.dataController addBirdSightingWithSighting:addController.birdSighting];
[[self tableView] reloadData];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
- (IBAction)cancel:(UIStoryboardSegue *)segue
{
if ([[segue identifier] isEqualToString:#"CancelInput"]) {
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"ShowSightingDetails"]) {
BirdsDetailViewController *detailViewController = [segue destinationViewController];
detailViewController.sighting = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
}
}
#end