I am trying to divide NSInteger with some number, but I am receiving errors.
This is what I am trying to do:
length = [corner count];
for (int i=0; i<length; i++) {
if ([resultDate rangeOfString:[corner objectAtIndex:i]].location != NSNotFound) {
cornerResult++;
}
}
cornerResultLabel.text = [NSString stringWithFormat:@"%i", cornerResult];
This works as it should.. I search through the array and count the results and write it.
But, I need cornerResult divided with 4. When I add cornerResult / 4 it shows me the error(as I wrote in comment). I have no idea why is this making problem.
you probably meant to divide the intValue
of the NSNumber
, not the NSNumber*
itself:
int num = number.intValue;
int result = num / 4;
(full code sample and error message would help)
你正在划分一个成为浮点数的int,而不是使用%f。
I fix it this way. First I defined int and after that I set NSInteger value to int and after that divide.
int helper = cornerResult;
helper = helper / 4;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.