Reputation: 171
I am having a problem passing an object from a TableView to a ViewController in an IOS app. I am using storyboard and have elected ARC and passing the delegate in my "prepareForSegue" method.
Here is my code in my TableView which segues via a push to another ViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NextViewController *vc = (NextViewController *)[segue destinationViewController];
vc.managedObjectContext = managedObjectContext;
if ([[segue identifier] isEqualToString:@"EditCategory"])
{
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// I get a red warning which states "Cast of 'NSInteger' (aka 'int') to 'Entity' is disallowed with ARC" on this line:
[vc setEntity:(Entity *)selectedIndex];
}
}
Does anybody have any suggestions for how I can pass my object from the TableView to the ViewController? I am new to programming and have tried various expressions but nothing seems to work.
Upvotes: 0
Views: 773
Reputation: 5033
The error you're getting has to do with types.
The class NextViewController
apparently has a method called -setEntity:
that takes an object of type Entity *
. The error is because you're trying to give -setEntity:
an argument of the wrong type. You're trying to give it an NSInteger
(which is a number like 0, 5, -999), but it wants an Entity
.
You're on the right track for passing data from the table view to the NextViewController
. You just need to do one of the following:
Entity
to -setEntity:
(does the Entity
class perhaps
have a constructor that takes an NSInteger
?)NextViewController
that takes an NSInteger
, and call that instead of -setEntity:
Upvotes: 1