我试图在我的主屏幕上的标签中显示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];
}