0
votes

I asked this question in the restkit google group, but realize now that it might actually be a more broad issue and not RK specific.

I've been going around in circles for a few hours on this one. I'm trying to populate a UITableView with data retrieved from a webservice and stored in objects using RestKits object mapping. Hitting the service, storing the objects all works beautifully.

The issue is when I try to reloadData for the Table. I'm getting this error -

'NSInvalidArgumentException', reason: '-[CoursesModel text]: unrecognized selector sent to instance and then app shuts down and 

takes me here: 
@autoreleasepool { 
return UIApplicationMain(argc, argv, nil, 
NSStringFromClass([RoundShoutAppDelegate class])); 
} 
Thread 1: signal SIGABRT 

CoursesModel is the model I setup. If I don't specify the tableview's delegate as the class (which I know I have to) then the courses load perfectly in the table view. But I'll get an error when i try to click on one of the cells (at didSelectRowAtIndexPath. So focusing on the fact that I have to specify a delegate, I know something is really messed up and I can;t figure it out.

I'm assuming something is getting released when it shouldn't, but data is in the _courses array. This is an ARC project by the way.

Here is some of the pertinent code, but if you need more let me know. If anyone has any info a at all to point me in the right direction that would be awesome! Thanks for your help!

MainViewController.h 
@interface MainViewController : UITableViewController <CLLocationManagerDelegate, RKObjectLoaderDelegate, UITableViewDelegate, UITableViewDataSource> { 
IBOutlet UITableView *coursesTableView; 
NSArray *_courses; 
} 

@end 

CoursesModel.h

@interface CoursesModel : NSObject { 
NSNumber* _courseID; 
NSString* _courseName; 
NSString* _city; 
NSString* _state; 
NSNumber* _distance; 
} 

@property (nonatomic, retain) NSNumber* courseID; 
@property (nonatomic, retain) NSString* courseName; 
@property (nonatomic, retain) NSString* city; 
@property (nonatomic, retain) NSString* state; 
@property (nonatomic, retain) NSNumber* distance; 
@end 

MainViewController.m

//Most of the code ommited for your sanity 
// All good up to this point 
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects: 
(NSArray*)objects { 
 //NSLog(@"Loaded courses %@", objects); 
_courses = objects; 
// There is data in _courses. 
NSLog(@"Loaded courses in array %@", _courses); 
[coursesTableView reloadData]; 

Delegate Methods:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGSize size = [[[_courses objectAtIndex:indexPath.row] text] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 9000)]; 
return size.height + 10; 
}
1
something is calling the method named -text, post that method, if it exists, or the caller. - CodaFi
As far as I can tell in my code, here is the only place where "text" is referenced directly - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGSize size = [[[_courses objectAtIndex:indexPath.row] text] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 9000)]; return size.height + 10; } --- However, i commented that out and returned 50 to test and error is still there. so i'm guessing that isnt it - K_C
@CodaFi - Thanks for looking into this for me. Let me know if you need more code. I'm gussing that code snippet isnt the "text" reference you're looking for, so I'm happy to dig in elsewhere. Thanks again! - K_C

1 Answers

2
votes

I see it now! Your delegate method

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

CGSize size = [[[_courses objectAtIndex:indexPath.row] text] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 9000)]; 

return size.height + 10; 

}

is wrong. NSArray has no method called -text, therefore it caused an unrecognized selector to be sent to NSArray. Why didn't the compiler warn you about this? If you need a string, use -stringValue.

And as for your delegate thing, this makes complete sense now, because not setting the delegate would not call this method on reload.