I am creating an rss feed app with a slide out navigation bar as shown here(http://www.appcoda.com/ios-programming-sidebar-navigation-menu/).
The app will load and RSS feeds will parse and appear on my main screen. You can click on a feed and it will lead to a webView to show that corresponding website. I will also have a navigation bar button on the top left to toggle the slide out menu. I am not able to proceed working on my app because it keeps crashing.BTW, I'm using a third party library called SWRevealViewController.Here is my MasterViewController:
//
// JSSMasterViewController.m
// News App
//
// Created by Steve on 4/5/14.
// Copyright (c) 2014 self.edu.steve. All rights reserved.
//
#import "JSSMasterViewController.h"
#import "JSSDetailViewController.h"
#import "SWRevealViewController.h"
#interface JSSMasterViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
}
#end
#implementation JSSMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://images.apple.com/main/rss/hotnews/hotnews.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = #selector(revealToggle:);
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
- (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 feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: #"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
[item setObject:title forKey:#"title"];
[item setObject:link forKey:#"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:#"title"]) {
[title appendString:string];
} else if ([element isEqualToString:#"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: #"link"];
[[segue destinationViewController] setUrl:string];
}
}
#end
Here is SideBar View controller that manages the Slide out menu:
//
// JSSSidebarViewController.m
// News App
//
// Created by Steve on 4/5/14.
// Copyright (c) 2014 self.edu.steve. All rights reserved.
//
#import "JSSSidebarViewController.h"
#import "SWRevealViewController.h"
#interface JSSSidebarViewController ()
#end
#implementation JSSSidebarViewController{
NSArray *menuItems;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
menuItems = #[#"title", #"news", #"comments", #"map", #"calendar", #"wishlist", #"bookmark", #"tag"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];
// Set the photo if it navigates to the PhotoView
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: #[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
#end
I am not able to find out the solution. Here is my logs:
2014-04-05 20:17:43.843 News App[4496:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101968495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016c799e objc_exception_throw + 43
2 CoreFoundation 0x000000010191f374 -[__NSArrayM insertObject:atIndex:] + 820
3 UIKit 0x00000001002d40da -[UIView(UIViewGestures) addGestureRecognizer:] + 199
4 News App 0x0000000100001ecf -[JSSMasterViewController viewDidLoad] + 719
5 UIKit 0x000000010036a59e -[UIViewController loadViewIfRequired] + 562
6 UIKit 0x000000010036a777 -[UIViewController view] + 29
7 UIKit 0x00000001006752e2 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 390
8 UIKit 0x00000001002b0ffa -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 1109
9 UIKit 0x00000001002b0b9f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
10 UIKit 0x00000001002b0aef -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101
11 UIKit 0x00000001002afdfe -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377
12 UIKit 0x000000010036e70a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147
13 UIKit 0x00000001002aab1b -[UIWindow addRootViewControllerViewIfPossible] + 490
14 UIKit 0x00000001002aac70 -[UIWindow _setHidden:forced:] + 282
15 UIKit 0x00000001002b3ffa -[UIWindow makeKeyAndVisible] + 51
16 UIKit 0x000000010026fc98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
17 UIKit 0x0000000100273a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
18 UIKit 0x0000000100284d4c -[UIApplication handleEvent:withNewEvent:] + 3189
19 UIKit 0x0000000100285216 -[UIApplication sendEvent:] + 79
20 UIKit 0x0000000100275086 _UIApplicationHandleEvent + 578
21 GraphicsServices 0x0000000103ae171a _PurpleEventCallback + 762
22 GraphicsServices 0x0000000103ae11e1 PurpleEventCallback + 35
23 CoreFoundation 0x00000001018ea679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
24 CoreFoundation 0x00000001018ea44e __CFRunLoopDoSource1 + 478
25 CoreFoundation 0x0000000101913903 __CFRunLoopRun + 1939
26 CoreFoundation 0x0000000101912d83 CFRunLoopRunSpecific + 467
27 UIKit 0x00000001002732e1 -[UIApplication _run] + 609
28 UIKit 0x0000000100274e33 UIApplicationMain + 1010
29 News App 0x0000000100002c23 main + 115
30 libdyld.dylib 0x00000001020005fd start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thank you for any Help!
The error is exactly what your error log says:
'*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
You are trying to insert an object to an array and that object is nil. In this particular case, it's this line that's causing problem:
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
You will need to alloc self.revealViewController.panGestureRecognizer first before adding it as the view's gesture recognizers.
One way to alloc the gesture recognizer:
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(someMethod:)];
[self.view addGestureRecognizer:gestureRecognizer];
Related
A single popover that is called from multiple different view controllers without a problem except for one particular view controller. All the view controllers descend from the same parent class and thus use the same function to display the popover. The function uses presentPopoverFromRectto display the popover in question. On the problem view controller I can see the popover's viewDidLoadfire then the app crashes with a invalid argument exception. I have no idea what UILabel its talking about or why its trying to get its length.
-(IBAction) showNormSelector:(id)sender
{
if (self.normSelectionPopover == nil)
{
Ace_Metrix_iPad_2AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"AceMetrixMOBILEHD_Storyboard" bundle:[NSBundle mainBundle]];
NSMutableDictionary* mdic = [[NSMutableDictionary alloc]initWithCapacity:4];
mdic[NSLocalizedStringFromTable(#"Industry", appDelegate.stringTableName,#"")] = #(IndustryType);
mdic[NSLocalizedStringFromTable(#"Category", appDelegate.stringTableName,#"")] = #(CategoryType);
mdic[NSLocalizedStringFromTable(#"Subcategory", appDelegate.stringTableName,#"")] = #(SubCategoryType);
mdic[NSLocalizedStringFromTable(#"Brand", appDelegate.stringTableName,#"")] = #(BrandType);
NSArray* arr = #[NSLocalizedStringFromTable(#"Industry", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Category", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Subcategory", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Brand", appDelegate.stringTableName,#"")];
self.popOver = (SelectorPopover*)[storyBoard instantiateViewControllerWithIdentifier:#"NormTypeSelector"];
[self.popOver setSelectionText:mdic];
[self.popOver setAllKeys:[NSMutableArray arrayWithArray:arr]];
[self.popOver setDelegate:self];
self.normSelectionPopover = [[UIPopoverController alloc] initWithContentViewController:self.popOver];
}
[self.popOver setCurrentSel:#(self.normType)];
[self.popOver.tableView reloadData];
[self.normSelectionPopover presentPopoverFromRect:self.normButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
SelectorPopover.m
#implementation SelectorPopover
#synthesize delegate;
#synthesize selectionText;
#synthesize allKeys;
#synthesize tag;
#synthesize currentSel;
-(void) viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) // before iOS 7
{
self.contentSizeForViewInPopover = CGSizeMake(135, [self.tableView rowHeight] * 4); // Depricated in iOS 7
}
else
{
self.preferredContentSize = CGSizeMake(135, [self.tableView rowHeight] * 4);
}
NSUInteger newIndex[] = {0, 0};
NSIndexPath* indexPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition: UITableViewScrollPositionNone];
}
/*
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation // Deprecated in iOS6
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.selectionText count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"SelectCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString* method = self.allKeys[indexPath.row];
cell.textLabel.text = method;
[cell.textLabel setTextColor:AMColorNeutralMidGrey38];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = nil;
NSNumber* uuid = (self.selectionText)[method];
if ([self.currentSel integerValue] == [uuid integerValue])
{
UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"checkmark_blue.png"]];
cell.accessoryView = checkmark;
[cell.textLabel setTextColor:AMColorTradeMarkLightBlue];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: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;
}
*/
#pragma mark -
#pragma mark Table view delegate
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.delegate)
{
NSString* key = self.allKeys[indexPath.row];
NSNumber* value = (NSNumber*) (self.selectionText)[key];
[self.delegate itemSelected:[value integerValue]];
}
}
#pragma mark -
#pragma mark Memory management
-(void) didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use.
}
-(void) viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
[super viewDidUnload];
}
-(void) dealloc {
self.delegate = nil;
}
#end
SelectorPopover.h
#protocol ItemSelectdDelegate
-(void)itemSelected:(HierarchyType) item;
#end
#interface SelectorPopover : UITableViewController
#property (nonatomic, weak) id<ItemSelectdDelegate> delegate;
#property (nonatomic,strong) NSMutableDictionary* selectionText;
#property (nonatomic,strong) NSMutableArray* allKeys;
#property (nonatomic,strong) NSNumber* currentSel;
#property (nonatomic) NSInteger tag;
#end
Call Stack:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x7b60bd30'
*** First throw call stack:
(
0 CoreFoundation 0x03b49df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02f52a97 objc_exception_throw + 44
2 CoreFoundation 0x03b51a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x03a9a9c7 ___forwarding___ + 1047
4 CoreFoundation 0x03a9a58e _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x03a33306 CFStringAppend + 374
6 CoreFoundation 0x03a30e2a __CFStringAppendFormatCore + 11754
7 CoreFoundation 0x03b26aa5 _CFStringCreateWithFormatAndArgumentsAux2 + 245
8 Foundation 0x004e9377 -[NSPlaceholderString initWithFormat:locale:arguments:] + 159
9 Foundation 0x004ecc22 +[NSString stringWithFormat:] + 89
10 UIKit 0x00aaa7a4 -[UIViewController _presentViewController:withAnimationController:completion:] + 2825
11 UIKit 0x00aad032 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
12 UIKit 0x00aace84 -[UIViewController presentViewController:animated:completion:] + 224
13 UIKit 0x01019011 -[UIPopoverController _presentShimmedPopoverFromRect:inView:permittedArrowDirections:animated:] + 217
14 UIKit 0x01019211 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 355
15 Ace Metrix MOBILE HD 0x00111242 -[AdDetailViewController showNormSelector:] + 3762
16 libobjc.A.dylib 0x02f687cd -[NSObject performSelector:withObject:withObject:] + 84
17 UIKit 0x0094779d -[UIApplication sendAction:to:from:forEvent:] + 99
18 UIKit 0x0094772f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
19 UIKit 0x00a7aa16 -[UIControl sendAction:to:forEvent:] + 69
20 UIKit 0x00a7ae33 -[UIControl _sendActionsForEvents:withEvent:] + 598
21 UIKit 0x00a7a09d -[UIControl touchesEnded:withEvent:] + 660
22 UIKit 0x00d7e257 _UIGestureRecognizerUpdate + 13225
23 UIKit 0x0099771b -[UIWindow _sendGesturesForEvent:] + 1356
24 UIKit 0x0099857f -[UIWindow sendEvent:] + 769
25 UIKit 0x0095daa9 -[UIApplication sendEvent:] + 242
26 UIKit 0x0096d8de _UIApplicationHandleEventFromQueueEvent + 20690
27 UIKit 0x00942079 _UIApplicationHandleEventQueue + 2206
28 CoreFoundation 0x03a6d7bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x03a632cd __CFRunLoopDoSources0 + 253
30 CoreFoundation 0x03a62828 __CFRunLoopRun + 952
31 CoreFoundation 0x03a621ab CFRunLoopRunSpecific + 443
32 CoreFoundation 0x03a61fdb CFRunLoopRunInMode + 123
33 GraphicsServices 0x04b5a24f GSEventRunModal + 192
34 GraphicsServices 0x04b5a08c GSEventRun + 104
35 UIKit 0x00945e16 UIApplicationMain + 1526
36 Ace Metrix MOBILE HD 0x00006cad main + 141
37 libdyld.dylib 0x03541ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think somewhere you are doing [label length] instead of [label.text length]
I'm new to iOS and its developing. I'm developing iPhone application.there i have UITableView and UIWebView. When i am pressing UITableview's cell, according to click there i want to load various webpages in my UIWebView. please find below the Errors i've got.
2014-07-05 08:25:59.319 WADTourisum[432:60b] myUrl-->2
2014-07-05 08:26:02.753 WADTourisum[432:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main.storyboard' in bundle NSBundle </Users/venushka/Library/Application Support/iPhone Simulator/7.1/Applications/3325DB09-FC4D-4B28-8DAF-5F9ABCAB8464/WADTourisum.app> (loaded)'
*** First throw call stack:
(
0 CoreFoundation 0x01a421e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0158f8e5 objc_exception_throw + 44
2 UIKit 0x007b3400 -[UIStoryboard name] + 0
3 WADTourisum 0x0001411e -[Essentialinfocontroller tableView:didSelectRowAtIndexPath:] + 174
4 UIKit 0x003399a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
5 UIKit 0x00339b14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
6 UIKit 0x0033e10e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
7 UIKit 0x0026d0aa ___afterCACommitHandler_block_invoke + 15
8 UIKit 0x0026d055 _applyBlockToCFArrayCopiedToStack + 403
9 UIKit 0x0026ce76 _afterCACommitHandler + 532
10 CoreFoundation 0x01a0a36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
11 CoreFoundation 0x01a0a2bf __CFRunLoopDoObservers + 399
12 CoreFoundation 0x019e8254 __CFRunLoopRun + 1076
13 CoreFoundation 0x019e79d3 CFRunLoopRunSpecific + 467
14 CoreFoundation 0x019e77eb CFRunLoopRunInMode + 123
15 GraphicsServices 0x03a365ee GSEventRunModal + 192
16 GraphicsServices 0x03a3642b GSEventRun + 104
17 UIKit 0x0024ff9b UIApplicationMain + 1225
18 WADTourisum 0x00004d1d main + 141
19 libdyld.dylib 0x02089701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Essentialinfocontroller.m
#import "Essentialinfocontroller.h"
#interface Essentialinfocontroller ()
#end
#implementation Essentialinfocontroller
#synthesize myWebview;
#synthesize courses;//dictionary type object
#synthesize coursekeys; //array type object
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile= [[NSBundle mainBundle]pathForResource:#"essentialinfo" ofType:#"plist"];
// NSLog(#"testing path %#",myfile);
courses=[[NSDictionary alloc]initWithContentsOfFile:myfile];
coursekeys =[courses allKeys];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [courses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell=[[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
NSString * currentCourseName =[coursekeys objectAtIndex:[indexPath row]];
[[cell textLabel]setText:currentCourseName];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
//implement stack method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main.storyboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"story"];
[self.navigationController pushViewController:viewController animated:YES];
}
if (indexPath.row==1) {
NSLog(#"myUrl-->2 ");
}
}
//end
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
DetailViewController.m
#implementation DetailViewController
#synthesize info;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url= [NSURL URLWithString:#"http://www.google.lk"];
NSURLRequest * requestURL= [NSURLRequest requestWithURL:url];
[info loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
This line raise the exception :
DetailViewController *temp =[[DetailViewController alloc]initWithNibName:#"DeatailViewController" bundle:[NSBundle mainBundle]];
The line above initialise a view controller with a nib file(.xib)
As you say in your comment, you are using storyboard so you should use UIStoryboard Class
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController identifier"];
Now, to get the identifier of your view controller :
Open your storyboard
Click on your view controller (Detail view controller here)
On the right side : Utilities, click on show the identity inspector (third button)
In the storyboard ID field, put the identifier (DetailViewController identifier for example)
Edit :
I think that the name of your storyboard is wrong. In your project you have a file called Main.storyboard or somethingElse.storyboard, so you should replace storyboard in this line :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"storyboard" bundle:nil]; by Main or somethingElse without the .storyboard extension
Then you replace DetailViewController identifier in this line UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController identifier"]; by the identifier of your view controller (story in your screenshot)
DetailViewController
#property(nonatomic,retain)NSString *myurl;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url= [NSURL URLWithString:myurl];
NSURLRequest * requestURL= [NSURLRequest requestWithURL:url];
[info loadRequest:requestURL];
}
Essentialinfocontroller
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){ //what ever you want row
DetailViewController *temp =[[DetailViewController alloc]initWithNibName:#"DeatailViewController" bundle:nil];
//or [[DetailViewController alloc]init];
temp.myurl = #"http://www.google.lk";
[self.navigationController pushViewController:temp animated:YES];
}
}
I have a UITableView setup within my view controller to populate with the JSON data that's being returned by a function. When I load MatchCenterViewController, the app crashes and I receive the following error:
2014-06-07 15:56:23.651 Parse+Storyboard[6848:607] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xaa29730
2014-06-07 15:56:23.825 Parse+Storyboard[6848:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xaa29730'
*** First throw call stack:
(
0 CoreFoundation 0x02a8c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0264a8e5 objc_exception_throw + 44
2 CoreFoundation 0x02b29243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02a7c50b ___forwarding___ + 1019
4 CoreFoundation 0x02a7c0ee _CF_forwarding_prep_0 + 14
5 UIKit 0x0156f94c -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2510
6 UIKit 0x0157323d -[UITableViewRowData numberOfRows] + 98
7 UIKit 0x013f0df2 -[UITableView noteNumberOfRowsChanged] + 120
8 UIKit 0x013f07a5 -[UITableView reloadData] + 814
9 UIKit 0x013f43b3 -[UITableView _reloadDataIfNeeded] + 65
10 UIKit 0x013f95f4 -[UITableView layoutSubviews] + 36
11 UIKit 0x01379964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x0265c82b -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x0064f45a -[CALayer layoutSublayers] + 148
14 QuartzCore 0x00643244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x006430b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x005a97fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x005aab85 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x006685b0 +[CATransaction flush] + 52
19 UIKit 0x013089bb _UIApplicationHandleEventQueue + 13095
20 CoreFoundation 0x02a1577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x02a1510b __CFRunLoopDoSources0 + 235
22 CoreFoundation 0x02a321ae __CFRunLoopRun + 910
23 CoreFoundation 0x02a319d3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x02a317eb CFRunLoopRunInMode + 123
25 GraphicsServices 0x02ce95ee GSEventRunModal + 192
26 GraphicsServices 0x02ce942b GSEventRun + 104
27 UIKit 0x0130af9b UIApplicationMain + 1225
28 Parse+Storyboard 0x00002cbd main + 141
29 libdyld.dylib 0x038e56d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've checked UIView tableView:numberOfRowsInSection that the error code refers to, and I don't see what could be causing this, as it simply tells it that there are 3 rows. Code and screenshots are below.
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *matchCenter;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];
cell.textLabel.text = [matchCenterDictionary objectForKey:#"Title"];// title of the first object
// if([matchCenterDictionary objectForKey:#"Price"] != NULL)
// {
// cell.detailTextLabel.text = [NSString stringWithFormat:#"$%#",[matchCenterDictionary objectForKey:#"Price"]];
// }
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.matchCenterArray = [[NSArray alloc] init];
//perform search with criteria just submitted
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (void)viewDidAppear:(BOOL)animated
{
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
You're setting the UITableViewDelegate and UITableViewDataSource of your tableView to the UIView and not your MatchCenterViewController in interface builder.
UIView doesn't implement UITableViewDataSource and that's why you are getting an unrecognized selector error.
You need to set the delegate and dataSource to the class that implements the delegate methods. In your case, that's your MatchCenterViewController.
Also another thing I notice, you're calling the PFCloud method both on viewDidLoad and viewDidAppear. You should only do that in one place, if you want it to execute one, add it to the viewDidLoad, if you want it to execute every time the view is shown, add it to viewDidAppear.
And another small thing: You should have methods in the order from top to bottom (in your file):
dealloc (if you have one)
initializer methods (init, initWithFrame, etc.)
Other methods, the related ones grouped up, usually separated with #pragma mark.
You need to set MatchCenterViewController class as dataSource and delegate for your matchCenter table view.
Add following 2 lines of code in initWithNibName function
[matchCenter setDelegate:self];
[matchCenter setDataSource:self];
I've programmatically created a UITableView within my MatchCenterViewController, however it doesn't seem to populate with the JSON data being returned by my cloud code function. It crashes and gives me the following error:
2014-06-08 20:56:23.762 Parse+Storyboard[9136:607] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x02a8c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0264a8e5 objc_exception_throw + 44
2 CoreFoundation 0x02a408b2 -[__NSArrayI objectAtIndex:] + 210
3 Parse+Storyboard 0x00005e6a -[MatchCenterViewController tableView:cellForRowAtIndexPath:] + 218
4 UIKit 0x0140311f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
5 UIKit 0x014031f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
6 UIKit 0x013e4ece -[UITableView _updateVisibleCellsNow:] + 2428
7 UIKit 0x013f96a5 -[UITableView layoutSubviews] + 213
8 UIKit 0x01379964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
9 libobjc.A.dylib 0x0265c82b -[NSObject performSelector:withObject:] + 70
10 QuartzCore 0x0064f45a -[CALayer layoutSublayers] + 148
11 QuartzCore 0x00643244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x006430b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
13 QuartzCore 0x005a97fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
14 QuartzCore 0x005aab85 _ZN2CA11Transaction6commitEv + 393
15 QuartzCore 0x006685b0 +[CATransaction flush] + 52
16 UIKit 0x013089bb _UIApplicationHandleEventQueue + 13095
17 CoreFoundation 0x02a1577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x02a1510b __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x02a321ae __CFRunLoopRun + 910
20 CoreFoundation 0x02a319d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x02a317eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x02ce95ee GSEventRunModal + 192
23 GraphicsServices 0x02ce942b GSEventRun + 104
24 UIKit 0x0130af9b UIApplicationMain + 1225
25 Parse+Storyboard 0x00002b4d main + 141
26 libdyld.dylib 0x038e56d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
From what I can understand, it's telling me that self.matchCenterArray is empty, but I can't seem to figure out why the array isn't populating with the JSON being returned.
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (nonatomic) IBOutlet NSString *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#property (strong, nonatomic) NSString *matchingCategoryCondition;
#property (strong, nonatomic) NSString *matchingCategoryLocation;
#property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
#property (strong, nonatomic) NSArray *matchCenterArray;
#end
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (nonatomic, strong) UITableView *matchCenter;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
// _matchCenter.dataSource = self;
// _matchCenter.delegate = self;
// [self.view addSubview:self.matchCenter];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_matchCenter.dataSource = self;
_matchCenter.delegate = self;
[self.view addSubview:self.matchCenter];
self.matchCenterArray = [[NSArray alloc] init];
}
- (void)viewDidAppear:(BOOL)animated
{
self.matchCenterArray = [[NSArray alloc] init];
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];
cell.textLabel.text = [matchCenterDictionary objectForKey:#"Title"];// title of the first object
// if([matchCenterDictionary objectForKey:#"Price"] != NULL)
// {
// cell.detailTextLabel.text = [NSString stringWithFormat:#"$%#",[matchCenterDictionary objectForKey:#"Price"]];
// }
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
JSON that's returned:
{
"Top 3" : [
{
"Title" : "Apple iPhone 5s (Latest Model) - 16GB - Silver (AT&T) Smartphone",
"Price" : "400.0",
"Image URL" : "http://thumbs2.ebaystatic.com/m/mewfVG0QbBiu1nZytMuAlZw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5s-Latest-Model-16GB-Silver-AT-T-Smartphone-/181431570117?pt:Cell_Phones"
},
{
"Title" : "Apple iPhone 5c (Latest Model) - 16GB - Pink (Verizon) Smartphone",
"Price" : "350.0",
"Image URL" : "http://thumbs4.ebaystatic.com/m/mMPAT67KjfCZF9oorbTf3uw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5c-Latest-Model-16GB-Pink-Verizon-Smartphone-/191204844039?pt:Cell_Phones"
},
{
"Title" : "Apple iPhone 5 16GB, White, works with Virgin Mobile US NEW",
"Price" : "359.99",
"Image URL" : "http://thumbs3.ebaystatic.com/m/m5x1uj1iSS2fr691tifrvrw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5-16GB-White-works-Virgin-Mobile-US-NEW-/141227441998?pt:Cell_Phones"
}
]
}
UITableView will request cells before your API call has returned data. Network request can take a long time, and if the user is not connected to the network it will fail completely. Don't assume that your network calls will return immediately.
And because you start your asynchronous (!) API call only in viewDidAppear: the tableView starts to request cells even before you have started the API call.
Since you have specified that there are 3 rows in your first section tableView:cellForRowAtIndexPath: tries to access this:
// for first row
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:0];
Which raises an out of bounds exception because your array is empty, and does not have an object at index 0.
Don't return 3 in tableView:numberOfRowsInSection: if you don't have 3 objects in your array, return the actual number of objects that are contained in your array:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.matchCenterArray count];
}
and to prevent your next crash, move the call where you register the cell to a place where self.matchCenter is not nil, i.e. after the alloc init of the tableView.
e.g.:
self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
/* ... */
[self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
I'm really new to iOS dev (and programming in general), and I would appreciate if you can explain when I get a SIGABRT error, what should I look into to go and fix?
I made a segue from a table view controller to another view controller and when I tap on a cell to preform the segue I get this:
This is the entire console:
2014-04-05 00:12:21.832 Robonote[20893:70b] -[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0
2014-04-05 00:12:21.874 Robonote[20893:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0'
*** First throw call stack:
(
0 CoreFoundation 0x0173d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014c08b6 objc_exception_throw + 44
2 CoreFoundation 0x017da903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172d90b ___forwarding___ + 1019
4 CoreFoundation 0x0172d4ee _CF_forwarding_prep_0 + 14
5 Robonote 0x00003d3f -[NMNotesListViewController prepareForSegue:sender:] + 287
6 UIKit 0x0076306c -[UIStoryboardSegueTemplate _perform:] + 156
7 UIKit 0x007630f9 -[UIStoryboardSegueTemplate perform:] + 115
8 UIKit 0x00310775 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1453
9 UIKit 0x00310924 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
10 UIKit 0x00314908 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
11 UIKit 0x0024b183 ___afterCACommitHandler_block_invoke + 15
12 UIKit 0x0024b12e _applyBlockToCFArrayCopiedToStack + 403
13 UIKit 0x0024af5a _afterCACommitHandler + 532
14 CoreFoundation 0x017054ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
15 CoreFoundation 0x0170541f __CFRunLoopDoObservers + 399
16 CoreFoundation 0x016e3344 __CFRunLoopRun + 1076
17 CoreFoundation 0x016e2ac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x016e28db CFRunLoopRunInMode + 123
19 GraphicsServices 0x036e29e2 GSEventRunModal + 192
20 GraphicsServices 0x036e2809 GSEventRun + 104
21 UIKit 0x0022ed3b UIApplicationMain + 1225
22 Robonote 0x0000357d main + 141
23 libdyld.dylib 0x01d7b701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the NMNotesListViewController.m :
import "NMNotesListViewController.h"
#import "NMCreateNotesViewController.h"
#interface NMNotesListViewController ()
#property (strong, nonatomic) NSMutableArray *notes;
#end
#implementation NMNotesListViewController
- (IBAction) unwindToList: (UIStoryboardSegue *) segue
{
NMCreateNotesViewController *source = [segue sourceViewController];
NMNote *note = source.note;
if (note != nil) {
[self.notes addObject:note];
[self.tableView reloadData];
}
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.notes = [[NSMutableArray alloc] init];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.notes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"NotesPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NMNote *note = [self.notes objectAtIndex:indexPath.row];
cell.textLabel.text = note.content;
return cell;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender
{
if ([[segue identifier] isEqualToString:#"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NSInteger indx = [self.tableView indexPathForCell:sender].row;
NMNote *note = self.notes[indx];
destination.passedInString = note.content;
}
}
//#pragma mark - delegate
//
//- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//}
#end
And this is the NMCreateNotesViewController.m :
#import "NMCreateNotesViewController.h"
#import "NMNotesListViewController.h"
#interface NMCreateNotesViewController () <UITextViewDelegate>
#property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
#end
#implementation NMCreateNotesViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// listen for keyboard hide/show notifications so we can properly adjust the table's height
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
#pragma mark - Notifications
- (void)adjustViewForKeyboardReveal:(BOOL)showKeyboard notificationInfo:(NSDictionary *)notificationInfo
{
// the keyboard is showing so ƒ the table's height
CGRect keyboardRect = [[notificationInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval animationDuration =
[[notificationInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect frame = self.textField.frame;
// the keyboard rect's width and height are reversed in landscape
NSInteger adjustDelta = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? CGRectGetHeight(keyboardRect) : CGRectGetWidth(keyboardRect);
if (showKeyboard)
frame.size.height -= adjustDelta;
else
frame.size.height += adjustDelta;
[UIView beginAnimations:#"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.textField.frame = frame;
[UIView commitAnimations];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
[self adjustViewForKeyboardReveal:YES notificationInfo:[aNotification userInfo]];
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
[self adjustViewForKeyboardReveal:NO notificationInfo:[aNotification userInfo]];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.saveButton) return;
if (self.textField.text.length > 0) {
self.note = [[NMNote alloc] init];
self.note.content = self.textField.text;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.passedInString != nil) {
self.textField.text = self.passedInString;
}
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The problem is in how you access the note you want to pass,
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NMNote *note = (NMNote*) sender;
destination.textField.text = note.content;
}
}
This should be,
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender
{
if ([[segue identifier] isEqualToString:#"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NSInteger indx = [self.tableView indexPathForCell:sender].row;
NMNote *note = self.notes[indx];
destination.passedInString = note.content;
}
}
Another problem you have is trying to set the value of a textField in the destination view controller from prepareForSegue. You can't do this because that controller's view hasn't been loaded yet, so its outlets will be nil. Instead, create a string property (I called it passedInString) in NMCreateNotesViewController, and use it to set the text field's text in the viewDidLoad method.
If your segue is connected from the cell to the next controller, then you shouldn't be calling performSegueWithIdentifier: in code. In fact, you don't need to implement didSelectRowAtIndexPath: at all.
First two lines of your console output tells you everything...
2014-04-05 00:12:21.832 Robonote[20893:70b] -[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0
2014-04-05 00:12:21.874 Robonote[20893:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0'
It looks like you are calling content method on UITableviewCell but this method isn't declarated anywhere. Try inspecting your code (view controller with UITableView inside) and find line where [UITableViewCell content] method is called.
And he got it... In your NMCreateNotesViewController there isn't any contet method but you're calling it in prepareForSegue:sender: method.