這是我的代碼。 「ViewController.m」數組參數在像「didSelectRowAtIndexPath」和「prepareForSegue」這樣的函數中沒有被調用
-(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;
}
}
我在兩個函數中都放入了斷點,並檢查參數「location」。他們都顯示「無」。
參數「位置」也是一個數組。如何在函數之間傳遞數組?
您可以複製 – Anupam 2015-04-02 06:57:04
歡迎粘貼水果類屬性的社會,你應該看看:https://開頭developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/FirstTutorial.html – LoVo 2015-04-02 06:57:19
什麼樣的參考您的財產位置使用弱或強?在我的,但它應該是強大的,以避免收回 – 2015-04-02 07:11:41