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 05-13-2011, 03:24 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default Reading from NSMutableArray Exception

Hi,
This is a strange problem. Look at the code below:
Code:
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	if (self.rowTitles != nil)
		cell.textLabel.text = [self.rowTitles count] > indexPath.row ? [self.rowTitles objectAtIndex:indexPath.row] : @"0";
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
	
	UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(170, 30, 500, 22)];
	textField.keyboardType = UIKeyboardTypeNumberPad;
        NSLog(@"The string at index is %@.", [self.values objectAtIndex:indexPath.row]);
	if (self.values != nil)
		textField.text = [self.values count] > indexPath.row ? [self.values objectAtIndex:indexPath.row] : @""; //Exception!!
	cell.accessoryView = textField;
    
    return cell;
The strangest thing is that the NSLog shows that there is a string at that index. However, when I set the textField's text (I tried using the setter without success), it causes the following exceptions:
Code:
2011-05-13 15:10:49.966 My App HD[1475:707] -[NSCFNumber _isNaturallyRTL]: unrecognized selector sent to instance 0x405e1d0
2011-05-13 15:10:49.983 My App HD[1475:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber _isNaturallyRTL]: unrecognized selector sent to instance 0x405e1d0'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x3604064f __exceptionPreprocess + 114
	1   libobjc.A.dylib                     0x35b99c5d objc_exception_throw + 24
	2   CoreFoundation                      0x360441bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
	3   CoreFoundation                      0x36043649 ___forwarding___ + 508
	4   CoreFoundation                      0x35fba180 _CF_forwarding_prep_0 + 48
	5   UIKit                               0x367958a7 -[UITextField setText:] + 38
	6   My Grapher HD                       0x0002078f -[VSRawDataInputController tableView:cellForRowAtIndexPath:] + 590
	7   UIKit                               0x367d99ed -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 516
	8   UIKit                               0x367d976b -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 34
	9   UIKit                               0x367d20cd -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 936
	10  UIKit                               0x367d127d -[UITableView layoutSubviews] + 140
	11  UIKit                               0x3677d5fb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 26
	12  CoreFoundation                      0x35fadf03 -[NSObject(NSObject) performSelector:withObject:] + 22
	13  QuartzCore                          0x317ccbb5 -[CALayer layoutSublayers] + 120
	14  QuartzCore                          0x317cc96d CALayerLayoutIfNeeded + 184
	15  QuartzCore                          0x317d21c5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 212
	16  QuartzCore                          0x317d1fd7 _ZN2CA11Transaction6commitEv + 190
	17  QuartzCore                          0x317cb055 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 56
	18  CoreFoundation                      0x36017a35 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16
	19  CoreFoundation                      0x36019465 __CFRunLoopDoObservers + 412
	20  CoreFoundation                      0x3601a75b __CFRunLoopRun + 854
	21  CoreFoundation                      0x35faaec3 CFRunLoopRunSpecific + 230
	22  CoreFoundation                      0x35faadcb CFRunLoopRunInMode + 58
	23  GraphicsServices                    0x312e441f GSEventRunModal + 114
	24  GraphicsServices                    0x312e44cb GSEventRun + 62
	25  UIKit                               0x367a6d69 -[UIApplication _run] + 404
	26  UIKit                               0x367a4807 UIApplicationMain + 670
	27  My Grapher HD                       0x00002abb main + 70
	28  My Grapher HD                       0x00002a70 start + 40
)
terminate called after throwing an instance of 'NSException'
The strings in the array were created with [NSString stringWithFormat:@"%g", number];
Please help if there's something I'm missing - thanks!
architectpianist is offline   Reply With Quote
Old 05-13-2011, 03:31 PM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Your NSLog does not prove the object is a string, as %@ will print the description of any object. According to the error message, you have an NSNumber. Double check the code that fills that array in the first place.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 05-13-2011, 04:18 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Default

Well, here's how I determined that it is an NSString:
Code:
if ([[self.values objectAtIndex:indexPath.row] isKindOfClass:[NSString class]])
        NSLog(@"%@ is a string.", [self.values objectAtIndex:indexPath.row]);
And the number of rows is the count of the values array, so it is being populated.
architectpianist is offline   Reply With Quote
Old 05-13-2011, 04:25 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 122
architectpianist is on a distinguished road
Wink

JasonR, you're right, it turned out that I was using a for loop to get numbers from a string, and at the end I was adding an NSNumber with the last number instead of an NSString (aka inconsistency). I thought I was getting the exception before the NSLog, but in fact the if statement above was being skipped because it was an NSNumber.

Thanks for your help!
architectpianist is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray, nsnumber, nsstring, uitextfield

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: 367
6 members and 361 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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