我有一个由三个字符串和一个数组组成的类。
该数组包含另一个对象列表。
当我尝试访问并向该数组添加新对象时,它不起作用。
例如;
CarList{
NSString *carName;
NSString *carId;
NSMutableArray *carTires;
}
CarTyres是另一个班级
visits = [[NSMutableArray alloc]init];
Visits * visit1 = [[Visits alloc]init];
visit1.visitDate = @"13.07.2013";
[visits addObject:visit1];
Visits * visit2 = [[Visits alloc]init];
visit2.visitDate = @"10.07.2013";
[visits addObject:visit2];
orderList = [[NSMutableArray alloc]init];
OrderList *order1 = [[OrderList alloc]init];
order1.monthName1 = @"Mart";
order1.monthName2 = @"Nisan";
order1.monthName3 = @"Mayıs";
Orders *firstOrder = [[Orders alloc]init];
firstOrder.orderName = @"Voltaren";
firstOrder.monthCount1 = @"20";
firstOrder.monthCount2 = @"43";
firstOrder.monthCount3 = @"11";
firstOrder.rangeMonthCount = @"74";
[order1.orders addObject:firstOrder];
[orderList addObject:order1];
在最后一行上没有添加对象。
如何解决?
答案 0 :(得分:0)
改为这个,希望这有助于你:)
//suppose u hav an instance
CarList{
NSString *carName;
NSString *carId;
NSMutableArray *carTires;
}
//in another class
CarTire{
NSString *tireName;
NSString *tireId;
}
CarList * carlist = [CarList alloc]init];
carlist.carName =@"Blabla";
carlist.carId =@"idx234";
CarTire *tire1 = [CarTire alloc]init];
tire1.tireName = @"Blibli";
tire1.tireId = @"idT211";
[carlist.carTires addObject:tire1];//you are adding to CarList object array