Here is my code. "ViewController.m"
-(void)viewDidLoad {
[super viewDidLoad];
Fruit *item1 = [Fruit new];
item1.name = @"Apple";
item1.price = @"1$ for one";
item1.image = @"apple.jpeg";
item1.location = [NSArray arrayWithObjects:@"Japan", @"Apple is good for health.", nil];
Fruit *item2 = [Fruit new];
item2.name = @"Banana";
item2.price = @"80 cents for one";
item2.image = @"banana.jpeg";
item2.location = [NSArray arrayWithObjects:@"Taiwan",@"Banana is good after exercise.", nil]
fruit = [NSMutableArray arrayWithObjects:item1,item2, nil];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Fruit *newRow = [fruit objectAtIndex:indexPath.row];
NSString * selectedFruit = newRow.name;
UIAlertView * messageAlert = [[UIAlertView alloc]initWithTitle:@"Row Selected"message:selectedFruit delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"hi", nil];
[messageAlert show];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showFruitDetail"])
{
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
FruitDetailViewController * destViewController = segue.destinationViewController;
Fruit *newRow = [fruit objectAtIndex:indexPath.row];
destViewController.detailFruit = newRow;
}
}
I put breakpoints in both of the two functions and check the parameter "location". They both show "nil".
The parameter "location" is also an array. How to deliver arrays among functions?