我是xcode的新手。我正在尝试将数组从一个视图传递到另一个视图。我想将 ProfileViewController 中的整数传递profileid
给 FavouritesViewController 中的数组。加载 FavouritesViewController 后,日志将显示数组。
这是我的代码:
ProfileViewController.h
- (IBAction)AddFavouritesClicked:(id)sender;
ProfileViewController.m
@synthesize profileid;
int profileid = 0;
- (IBAction)AddFavouritesClicked:(id)sender {
FavouritesViewController *favController = [[FavouritesViewController alloc]init];
[favController.favouritesArray initWithObjects:[NSNumber numberWithInt:profileid], nil];
NSLog(@"%@", favController.favouritesArray);
}
收藏夹ViewController.h
@interface FavouritesViewController : UITableViewController
{
NSMutableArray *favouritesArray;
}
@property(nonatomic, retain)NSArray *favouritesArray;
@end
收藏夹ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", favouritesArray);
}
到目前为止,favouritesArray
价值始终是null
任何帮助将不胜感激。提前致谢!
这是我每次单击Addtofavoutites
按钮时的日志
2013-01-27 22:54:52.865 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:10.958 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:11.705 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:12.191 Ad&Promo[8058:c07] (
2
)
但相反,我希望它看起来像这样..
2013-01-27 22:54:52.865 Ad&Promo[8058:c07] (
2,2,2,2
)