NSMutableArray
メイン画面のラベルに、画面が最初に読み込まれたとき、および[追加]ボタンを押すたびのサイズを表示しようとしていますが、「式の結果が未使用です」などのエラーが表示されます。私はいくつかのオプションを試しましたが、それでも成功しませんでした...あなたの入力を教えてください、ありがとう!:)
int arraySize;
NSMutableArray *arrRaceCars;
- (void)viewDidLoad
{
[super viewDidLoad];
arrRaceCars = [[NSMutableArray alloc]init];
arraySize = [self numberOfObjectsInArray:arrRaceCars]; // call for a method that should return the number of objects in array
self.lblCarsCount.text = @"%d cars in the race", &arraySize;
}
// ...part of the Add button validation; in case that everything is OK, the code below should add an object to the array and change the display of number of cars in the array in the label
else
{
self.carType = [segmentedSelectCar titleForSegmentAtIndex:segmentedSelectCar.selectedSegmentIndex];
self.carName = self.txtCarName.text;
self.carSpeed = [self.txtCarSpeed.text intValue];
car* newCar = [[car alloc]initCarWithName:carName carType:carType carMaxSpeed:carSpeed];
NSLog(@"Car type is: %@, Car name is: %@, Car speed is: %d", self.carType, self.carName, self.carSpeed);
[arrRaceCars addObject:newCar];
arraySize = [self numberOfObjectsInArray:arrRaceCars];
self.lblCarsCount.text = @"%d cars in the race", &arraySize; // this is the problematic line
[self alertMessage:@"addNewCar" :@"Your car has been added!" :nil :@"OK" :nil];
}
// this is the method that should return the number of objects within the array
-(int) numberOfObjectsInArray : (NSMutableArray*) arrayToCheck
{
return [arrayToCheck count];
}