Reputation: 47
I am sending some object, when pressing cell in my table to the other view, which have to show detail of that cell.
And when I try to change the label (on the second view) text, I get:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell nameOfItem]: unrecognized selector sent to instance 0x7f8e7ab5ed40'
My object:
@interface Item : NSObject
@property (strong,nonatomic) NSString * nameOfItem;
@property (strong,nonatomic) NSString * descriptionOfItem;
@property (strong,nonatomic) NSString * categoryOfItem;
-(instancetype)initItem:(NSString *)name category:(NSString *)category description:(NSString *)description;
-(NSComparisonResult)compare:(Item *)otherItem;
@end
My cell:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray* sortedItems = [[NSMutableArray alloc]initWithArray:[ItemsTable sortItems:self.itemsTable.items]];
self.itemsTable.items = sortedItems;
listOfItems = [NSArray arrayWithArray:self.itemsTable.items];
UITableViewCell *cell;
NSString *sectionTitle = [[self.itemsTable categoriesOfItemsTable] objectAtIndex:indexPath.section];
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
NSInteger index = [indexPath row];
cell.textLabel.text = ((Item *)[[self.itemsTable listOfItemsInCategory:sectionTitle] objectAtIndex:index]).nameOfItem;
return cell;
}
My row selecting:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *category = [[self.itemsTable categoriesOfItemsTable] objectAtIndex:indexPath.section];//get category of selected item
Item *testItem = [[self.itemsTable listOfItemsInCategory:category] objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"IntoInfoPage" sender:testItem];
}
My prepare for segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
...
if ([segue.identifier isEqualToString:@"IntoInfoPage"]){
if ([segue.destinationViewController isKindOfClass:[InfoViewController class]]){
InfoViewController *fivc = (InfoViewController *)segue.destinationViewController;
fivc.gotchaItem = sender;
}
}
}
and my second view:
@interface InfoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UILabel *categoryOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UITextView *descriptionOfFullInfoItem;
@end
@implementation InfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (self.gotchaItem)
{
self.nameOfFullInfoItem.text = [NSString stringWithFormat:@"Name: %@",self.gotchaItem.nameOfItem];
self.categoryOfFullInfoItem.text = [NSString stringWithFormat:@"Category: %@",self.gotchaItem.categoryOfItem];
self.descriptionOfFullInfoItem.text = [NSString stringWithFormat:@"%@",self.gotchaItem.descriptionOfItem];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Exception appears at line, that is in my second view:
#import "InfoViewController.h"
@interface InfoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameOfFullInfoItem; //Here!
@property (weak, nonatomic) IBOutlet UILabel *categoryOfFullInfoItem;
@property (weak, nonatomic) IBOutlet UITextView *descriptionOfFullInfoItem;
@end
Upvotes: 2
Views: 92
Reputation: 16827
At first I would agree with the other answers, but you are saying that your object is an Item, so it leads me to think of this answer:
Have you checked that this outlet @property (weak, nonatomic) IBOutlet UILabel *nameOfFullInfoItem;
is properly connected to the UILabel? Go into your interface builder and verify that only this label is connected to this outlet and nothing else.
Upvotes: 0
Reputation: 846
Your app is being crashed in following line
self.nameOfFullInfoItem.text = [NSString stringWithFormat:@"Name: %@",self.gotchaItem.nameOfItem];
Here self.gotchaItem appears to be a UITableViewCell. Thats why you can't call nameOfItem from this object. Make sure that you are sending the correct item object and self.gotchaItem should be an object of Item class.
Upvotes: 0
Reputation: 19239
The error is telling you that you are calling nameOfItem
method on a UITableViewCell
. That alone would be enough, but you also have the stack trace, it shouldn't be difficult to track it down.
In your attached code, this is very suspicious:
cell.textLabel.text = ((Item *)[[self.itemsTable listOfItemsInCategory:sectionTitle] objectAtIndex:index]).nameOfItem;
Set a breakpoint on that line and make sure that it's a Item
and not a UITableViewCell
.
Upvotes: 1