0

我有一个由三个字符串和一个数组组成的类。

该数组包含另一个对象列表。

当我尝试访问并将新对象添加到该数组时,它不起作用。

例如;

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];

在最后一行没有添加对象。

如何解决?

4

1 回答 1

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


于 2013-08-02T12:53:58.887 回答