数组参数在像“didSelectRowAtIndexPath”和“prepareForSegue”这样的函数中没有被调用
这是我的代码。 “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:@"*",@"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”。他们都显示“无”。
参数“位置”也是一个数组。如何在函数之间传递数组?
“location”属性应该使用“strong”引用来避免ARC自动释放。
@property(nonatomic, strong) NSArray * location;
入住#1以下链接了解强VS弱引用Differences between strong and weak in objective-c
非常感谢。 :) – 2015-04-02 08:27:18
如果您满意我的回复,请将其标为您的问题答案。 – 2015-04-02 08:49:45
哦,当然。我忘了。 :) 绿色复选标记正确吗? – 2015-04-02 09:21:34
您可以复制 – 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