如何初始化目标C空的可变数组 [英] How to initialize an empty mutable array in Objective C
问题描述
我有对象(卡车)与填充的tableview各种属性的列表。当您点击他们,他们去一个单独的页面卡车。还有一个附加按钮,将它们添加到收藏列表中的另一个tableview中。如何在可可初始化一个空的可变数组?
我有以下的code:
- (IBAction为)addTruckToFavorites:(ID)发件人:(FavoritesViewController *)控制器
{
[controller.listOfTrucks ADDOBJECT:((Truck_Tracker_AppAppDelegate *)[UIApplication的sharedApplication] .delegate).selectedTruck];}
更新:
使用新的语法,你可以使用:
的NSMutableArray * myArray的= [NSMutableArray的新]
原来的答复:
例如:
的NSMutableArray * myArray的= [[NSMutableArray里的alloc]初始化];
和<一个href=\"http://stackoverflow.com/questions/5423211/difference-between-nsmutablearray-array-vs-nsmutablearray-alloc-init\">here你找出原因(类和实例方法之间的差值)
I have a list of objects (trucks) with various attributes that populate a tableview. When you tap them they go to an individual truck page. There is an add button which will add them to the favorite list in another tableview. How do I initialize an empty mutable array in Cocoa?
I have the following code:
-(IBAction)addTruckToFavorites:(id)sender:(FavoritesViewController *)controller
{
[controller.listOfTrucks addObject: ((Truck_Tracker_AppAppDelegate *)[UIApplication sharedApplication].delegate).selectedTruck];
}
Update:
With new syntax you can use:
NSMutableArray *myArray = [NSMutableArray new];
Original answer:
for example:
NSMutableArray *myArray = [[NSMutableArray alloc] init];
And here you find out why (difference between class and instance method)
这篇关于如何初始化目标C空的可变数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!