Reputation: 91
I have a custom Cell class that holds a nameLabel and a gameLabel..
@property (nonatomic, strong) IBOutlet UILabel *nameLabel;
@property (nonatomic, strong) IBOutlet UILabel *gameLabel;
These both are populated from a protocol on a separate view which the user fills out and hits done. These then fill a TableView.
In order to populate the list on my tableview I have this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PlayerCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"PlayerCell"];
Player *player = [self.players objectAtIndex:indexPath.row];
cell.nameLabel.text = player.name;
cell.gameLabel.text = player.game;
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellbg.png"]];
return cell;
}
My questions is I am then trying to get the nameLabel and gameLabel to segue into a UIViewController when the populated TableViewCELL is touched but I am getting a SigAbrt error. heres my code for the seperate segues.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"AddPerson")] {
UINavigationController *navigationController = segue.destinationViewController;
PlayerDetailsViewController *playerDetailsViewController =[[navigationController viewControllers] obectAtIndex:0];
playerDetailsViewController.delegate = self;
} else if ([segue.identifier isEqualToString:@"ViewPerson"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PlayerProfileViewController *dvc = [segue destinationViewController];
dvc.personName = [players objectAtIndex:indexPath.row];
}
players being my NSMutableArray and personName being my NSString that I have in my Destination View Controller along with the corresponding label. and finally the sigabrt that I get with this comes from this code in my Destination View Controller
-(void)viewDidLoad {
[super viewDidLoad];
personLabel.text = personName; <-----WHERE THE SIGABRT TAKES ME
Any direction on where I am going wrong would be great I am still new
Upvotes: 0
Views: 680
Reputation: 104092
You gave personName the value of [players objectAtIndex:indexPath.row] in prepareForSegue. The class of that object is Player, not NSString, so you can't set a label's text with it. I suspect you want personName.name (and you should probably change the name to player or selectedPlayer if you want to pass a Player object, or pass just the name, rather than the Player object).
Upvotes: 1