I'm trying to create an app kinda like a dictionary and i have the table view with cells working but when i click on a word to go to the detail veiw controller the app crashes and gives me a "Thread 1: signal SIGABRT" error. I'm using a plist to put my data in. I think the problem is in here somewhere in this method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *theInfo = [info objectAtIndex:indexPath.row];
if(!self.detailViewController){
self.detailViewController=[[DetailViewController alloc]
initWithNibName:@"DetailViewController" bundle:nil];
}
self.detailViewController.detailItem = theInfo;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
MasterViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
@interface MasterViewController ()
@property NSMutableArray *objects;
@end
@implementation MasterViewController
@synthesize detailViewController= _detailViewController;
@synthesize name,info;
- (void)awakeFromNib {
[super awakeFromNib];
}
- (void)viewDidLoad {
self.navigationItem.title=@"Rocks";
NSString *dataFile = [[NSBundle mainBundle ] pathForResource:@"Data" ofType:@"plist"];
_Rocks = [[NSDictionary alloc] initWithContentsOfFile:dataFile];
name = [_Rocks objectForKey:@"Name"];
info = [_Rocks objectForKey:@"Info"];
[super viewDidLoad];
/
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
/
}
- (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];
[[segue destinationViewController] setDetailItem:object];
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
/
return[name count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
/
/
NSString *nameOfRock = [name objectAtIndex:indexPath.row];
cell.textLabel.text = nameOfRock;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
/
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) {
/
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *theInfo = [info objectAtIndex:indexPath.row];
if(!self.detailViewController){
self.detailViewController=[[DetailViewController alloc]
initWithNibName:@"DetailViewController" bundle:nil];
}
self.detailViewController.detailItem = theInfo;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
@end
MasterViewController.h
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface MasterViewController : UITableViewController
@property (nonatomic, strong) NSDictionary *Rocks;
@property (nonatomic ,strong) NSArray *name;
@property (nonatomic, strong) NSArray *info;
@property (strong, nonatomic) DetailViewController *detailViewController;
@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 ()
- (void)configureView;
@end
@implementation DetailViewController
@synthesize detailItem=_detailItem;
@synthesize detailDescriptionLabel= _detailDescriptionLabel;
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
/
[self configureView];
}
}
- (void)configureView {
/
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
/
[self configureView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
/
}
@end