Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2012, 01:05 PM   #1 (permalink)
generic twenty-something
 
jakerocheleau's Avatar
 
Join Date: Dec 2011
Location: Massachusetts
Age: 20
Posts: 54
jakerocheleau is on a distinguished road
Default UITableView Crashes Whenever Going Beyond Total Cell Values

So I have a small plist loaded into a UITableView which displays different endings to a game. Currently when you flick either up or down beyond the table's 8 total values the app crashes and Xcode displays this error:

Code:
2012-02-08 14:02:28.074 SaveTheHomeland[3995:f803] -[__NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6a5add0
2012-02-08 14:02:28.079 SaveTheHomeland[3995:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6a5add0'
*** First throw call stack:
(0x13bc052 0x154dd0a 0x13bdced 0x1322f00 0x1322ce2 0xace0f 0xad589 0x98d44 0xa7851 0x52322 0x13bde72 0x1d6692d 0x1d70827 0x1cf6fa7 0x1cf8ea6 0x1d9237a 0x1d921af 0x1390966 0x1390407 0x12f37c0 0x12f2db4 0x12f2ccb 0x12a5879 0x12a593e 0x13a9b 0x23f8 0x2355 0x1)
terminate called throwing an exception
I'm trying to build the app programmatically with no Storyboard whatsoever. I don't think this is the problem, though.. would love any help I can get on this issue.

You can download my source code if you wanna run it within Xcode yourself.
__________________
I write, design apps, code Objective-C, and research my life away.
jakerocheleau is offline   Reply With Quote
Old 02-08-2012, 01:08 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

The delegate message is being sent to an NSString. Sounds like you have a memory management problem. Or you've assigned the wrong object as the delegate.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 03:45 PM   #3 (permalink)
generic twenty-something
 
jakerocheleau's Avatar
 
Join Date: Dec 2011
Location: Massachusetts
Age: 20
Posts: 54
jakerocheleau is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
The delegate message is being sent to an NSString. Sounds like you have a memory management problem. Or you've assigned the wrong object as the delegate.
not sure I follow you but what is the 'delegate method'?

I'm using an NSString to fill in the title for each cell, and beyond my 8 cells there are no titles left. So the script may be trying to find an NSString which doesn't exist, then crashing?

I have a screenshot below, and I also added my AppDelegate code since this may be useful? Been debugging for a couple of hours and it has me wracking my brain.



Code:
# AppDelegate.h
#import <UIKit/UIKit.h>

#import "EndingsTableViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
Code:
# AppDelegate.m
#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    EndingsTableViewController *endingsController = [[EndingsTableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:endingsController];
    
    [self.window addSubview:navController.view];
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

@end
__________________
I write, design apps, code Objective-C, and research my life away.
jakerocheleau is offline   Reply With Quote
Old 02-08-2012, 04:03 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

See the link in my signature for guidance.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 04:14 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

you may be setting the numberOfRowsInSection too high for the cellForRowAtIndexPath function to handle. Those two need to be in sync, especially if you are using arrays.

You can always try commenting out most of the code in your cellForRowAtIndexPath function and then add it back in 1 line at a time until you find the problem.
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 02-08-2012, 04:18 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by RickSDK View Post
you may be setting the numberOfRowsInSection too high for the cellForRowAtIndexPath function to handle. Those two need to be in sync, especially if you are using arrays.

You can always try commenting out most of the code in your cellForRowAtIndexPath function and then add it back in 1 line at a time until you find the problem.
That would be an array out of bounds error. That's not what this is.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 05:06 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Why not set an Exception Breakpoint on all exceptions to see what line of code is failing. That way you wont be returned to the AppDelegate code where you really can't see what caused the issue.

Quote:
Originally Posted by BrianSlick View Post
That would be an array out of bounds error. That's not what this is.
GHuebner is offline   Reply With Quote
Old 02-08-2012, 05:19 PM   #8 (permalink)
generic twenty-something
 
jakerocheleau's Avatar
 
Join Date: Dec 2011
Location: Massachusetts
Age: 20
Posts: 54
jakerocheleau is on a distinguished road
Default

Quote:
Originally Posted by GHuebner View Post
Why not set an Exception Breakpoint on all exceptions to see what line of code is failing. That way you wont be returned to the AppDelegate code where you really can't see what caused the issue.
yeah I'm not familiar with how to do that but I recall reading about it on Stack.

NSLog some type of formatted output?
__________________
I write, design apps, code Objective-C, and research my life away.
jakerocheleau is offline   Reply With Quote
Old 02-08-2012, 05:51 PM   #9 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

There are really only 2 possibilities here:

1. The wrong object has been set as the delegate
2. The object set as the delegate has died

That's pretty much it.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 06:11 PM   #10 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

It looks like your initial error is also now different than the current one you posted.

Initial Exception:

'NSInvalidArgumentException', reason: '-[__NSCFString tableView:cellForRowAtIndexPath:]

Current Exception:

'NSInvalidArgumentException', reason: '-[__NSCFArray tableView:cellForRowAtIndexPath:]




Quote:
Originally Posted by BrianSlick View Post
There are really only 2 possibilities here:

1. The wrong object has been set as the delegate
2. The object set as the delegate has died

That's pretty much it.
GHuebner is offline   Reply With Quote
Old 02-08-2012, 06:16 PM   #11 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

When the receiving object class changes in an error message, that suggests memory management problem. So that would be #2 I mentioned above.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 06:35 PM   #12 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Thanks Brian,

I noticed the discrepancy but didnt know the link to memory management issues. Now at least I can look for that when I am debugging as well.

Quote:
Originally Posted by BrianSlick View Post
When the receiving object class changes in an error message, that suggests memory management problem. So that would be #2 I mentioned above.
GHuebner is offline   Reply With Quote
Old 02-08-2012, 07:38 PM   #13 (permalink)
generic twenty-something
 
jakerocheleau's Avatar
 
Join Date: Dec 2011
Location: Massachusetts
Age: 20
Posts: 54
jakerocheleau is on a distinguished road
Default

got it! The issue is with my UITableViewController releasing in memory.

This has something to do with ARC.. anyways in my AppDelegate.m I just changed this line:

Code:
[self.window addSubview:navController.view];
with this:

Code:
[self.window setRootViewController:navController];
and now the whole thing runs great. Plus now I know going forward on future apps
__________________
I write, design apps, code Objective-C, and research my life away.
jakerocheleau is offline   Reply With Quote
Old 02-08-2012, 07:46 PM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Nothing to do with ARC. Keeping the view alive (the first case) doesn't mean anything as far as keeping the view controller alive. The second case, which is indeed what you should be doing these days, keeps the controller alive.

I was trying to figure out how you'd have the table view alive while it's view controller died. Now I understand.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 389
14 members and 375 guests
7twenty7, chiataytuday, chits12345, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, ryantcb, stanny, xerohuang, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:23 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0