iOS app crashes when sending text from one ViewController to the another - ios

I want to send the text that a user inputs into the itemSearch UITextField in the SearchViewController over to MatchCenterViewController, so that it can use it in a function.
I've made the itemSearch property public by placing its IBOutlet in SearchViewController's header. It doesn't seem to send over successfully during the segue however, as it crashes when the eBayMatchCenterSearch function runs during the ShowMatchCenterSegue.
Error message:
2014-05-21 15:47:17.785 Parse+Storyboard[8787:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x02a881e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026468e5 objc_exception_throw + 44
2 CoreFoundation 0x02a4e376 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390
3 CoreFoundation 0x02a7bc29 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 73
4 Parse+Storyboard 0x00004c09 -[MatchCenterViewController viewDidLoad] + 329
5 UIKit 0x0142533d -[UIViewController loadViewIfRequired] + 696
6 UIKit 0x014255d9 -[UIViewController view] + 35
7 UIKit 0x0143f942 -[UINavigationController _startCustomTransition:] + 778
8 UIKit 0x0144c8f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
9 UIKit 0x0144d4e9 -[UINavigationController __viewWillLayoutSubviews] + 57
10 UIKit 0x0158e0d1 -[UILayoutContainerView layoutSubviews] + 213
11 UIKit 0x01375964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x0265882b -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x0064b45a -[CALayer layoutSublayers] + 148
14 QuartzCore 0x0063f244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x0063f0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x005a57fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x005a6b85 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x005a7258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
19 CoreFoundation 0x02a5036e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
20 CoreFoundation 0x02a502bf __CFRunLoopDoObservers + 399
21 CoreFoundation 0x02a2e254 __CFRunLoopRun + 1076
22 CoreFoundation 0x02a2d9d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x02a2d7eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x02ce55ee GSEventRunModal + 192
25 GraphicsServices 0x02ce542b GSEventRun + 104
26 UIKit 0x01306f9b UIApplicationMain + 1225
27 Parse+Storyboard 0x00002b0d main + 141
28 libdyld.dylib 0x038e2701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SearchViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <Parse/PFCloud.h>
#import "CriteriaViewController.h"
#interface SearchViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIButton *nextButtonOutlet;
#property (nonatomic, copy) NSString *topCategory1;
#property (nonatomic, copy) NSString *topCategory2;
#property (nonatomic, copy) NSNumber *topCategoryId1;
#property (nonatomic, copy) NSNumber *topCategoryId2;
#property (weak, nonatomic) IBOutlet UITextField *itemSearch;
#end
SearchViewController.m:
#import "SearchViewController.h"
#import "MatchCenterViewController.h"
#import "SearchCategoryChooserViewController.h"
#interface SearchViewController ()
#property (weak, nonatomic) IBOutlet UIButton *nextButton;
#end
#implementation SearchViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.nextButtonOutlet addTarget:self action:#selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)nextButton:(id)sender
{
if (self.itemSearch.text.length > 0) {
[PFCloud callFunctionInBackground:#"eBayCategorySearch"
withParameters:#{#"item": self.itemSearch.text}
block:^(NSDictionary *result, NSError *error) {
NSLog(#"'%#'", result);
// Parses results
NSArray *resultArray = [result objectForKey:#"results"];
// Number of Top Categories
NSDictionary *dictionary0 = [resultArray objectAtIndex:0];
NSNumber *numberOfTopCategories = [dictionary0 objectForKey:#"Number of top categories"];
// Ids of the Top Categories
NSDictionary *dictionary1 = [resultArray objectAtIndex:1];
NSArray *topCategoryIdsArray = [dictionary1 objectForKey:#"Top category Ids"];
// Names of the Top Categories
NSDictionary *dictionary2 = [resultArray objectAtIndex:2];
NSArray *topCategoryNamesArray = [dictionary2 objectForKey:#"Top category names"];
// Number of Top Categories matching User Categories
NSDictionary *dictionary3 = [resultArray objectAtIndex:3];
NSNumber *numberOfMatches = [dictionary3 objectForKey:#"Number of matches"];
// Names of Top Categories matching User Categories
NSDictionary *dictionary4 = [resultArray objectAtIndex:4];
NSArray *userCategoriesThatMatchSearch = [dictionary4 objectForKey:#"User categories that match search"];
// Defines where each topCategory name will come from
self.topCategory1 = [topCategoryNamesArray objectAtIndex:0];
if ([numberOfTopCategories intValue] == 2) {
self.topCategory2 = [topCategoryNamesArray objectAtIndex:1];
}
// Defines where each topCategory ID will come from
self.topCategoryId1 = [topCategoryIdsArray objectAtIndex:0];
if ([numberOfTopCategories intValue] == 2) {
self.topCategoryId2 = [topCategoryIdsArray objectAtIndex:1];
}
if (!error) {
// Decides which segue is taken based on results
// if 1 match found clear categoryResults and top2 array
if ([numberOfMatches intValue] == 1 ){
[self performSegueWithIdentifier:#"ShowMatchCenterSegue" sender:self];
}
// if 2 matches found
else if ([numberOfMatches intValue] == 2){
[self performSegueWithIdentifier:#"ShowUserCategoryChooserSegue" sender:self];
//default to selected categories criteria -> send to matchcenter -> clear categoryResults and top2 array
}
// if no matches found, and 1 top category is returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 1) {
[self performSegueWithIdentifier:#"ShowCriteriaSegue" sender:self];
}
// if no matches are found, and 2 top categories are returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 2) {
[self performSegueWithIdentifier:#"ShowSearchCategoryChooserSegue" sender:self];
}
}
}];
}
}
#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
{
if ([segue.identifier isEqualToString:#"ShowMatchCenterSegue"]) {
MatchCenterViewController *controller = (MatchCenterViewController *) segue.destinationViewController;
// Send over the search query
controller.itemSearch.text = self.itemSearch.text;
}
else if([segue.identifier isEqualToString:#"ShowSearchCategoryChooserSegue"]){
SearchCategoryChooserViewController *controller = (SearchCategoryChooserViewController *) segue.destinationViewController;
// Send over the search query as well as both categories to the Category Chooser VC
controller.itemSearch.text = self.itemSearch.text;
controller.topCategory1 = self.topCategory1;
controller.topCategory2 = self.topCategory2;
controller.topCategoryId1 = self.topCategoryId1;
controller.topCategoryId2 = self.topCategoryId2;
}
else if([segue.identifier isEqualToString:#"ShowCriteriaSegue"]){
CriteriaViewController *controller = (CriteriaViewController *) segue.destinationViewController;
// Send over the search query as well as the specific category to CriteriaVC to use
controller.itemSearch = self.itemSearch.text;
controller.chosenCategory = self.topCategoryId1;
}
}
#end
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (nonatomic) IBOutlet UITextField *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#end
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *matchCenter;
#property (strong, nonatomic) NSArray *itemsArray;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//perform search with criteria just submitted
[PFCloud callFunctionInBackground:#"eBayMatchCenterSearch"
withParameters:#{#"item": self.itemSearch.text,
#"minPrice": #"250",
#"maxPrice": #"400",
#"itemCondition": #"New",
// #"itemLocation": #"US",
}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(#"The result is '%#'", 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

itemSearch is an IBOutlet and therefore won't be instantiated until the view loads. Setting its text value in prepareForSegue means you're setting the text value of nil.
Create a NSString property in your destination controller and set that during the segue. Then copy it to itemSearch.text in viewDidLoad.

Related

Displaying a popover crashes my iOS 8 app

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]

Exception : Could not load NIB in bundle

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];
}
}

numberOfRowsInSection is causing unrecognized selector crash

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];

UITableView array returning error 'index 0 beyond bounds for empty array'

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"];

How do I understand where is my bug when I get a SIGABRT error?

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.

Resources