English 中文(简体)
B. 区分目标C中的变量
原标题:Dividing variables in Objective-C

so I need to divide on variable by a number. How can I do this? I know about the C functions of DIV and MOD, but do not know how to use them in objective-C/cocoa-touch. Heres an example of my code.

// hide the previous view
scrollView.hidden = YES;

//add the new view
scrollViewTwo.hidden = NO;

NSUInteger across;
int i;
NSUInteger *arrayCount;
// I need to take arrayCount divided by three and get the remainder

When I try to use / or % I get the error "Invalid operands to binary expression ( NSUInteger and int) Thanks for any help

最佳回答

首先,arrayCount是否真正成为点?

任何方面,如果是<条码>,则。 您只是要指出这一点......

NSInteger arrayCountValue = *arrayCount;

......并使用<条码>/(供司使用)和<条码>%(取用模块):

NSInteger quotient = arrayCountValue / 3;
NSInteger rest = arrayCountValue % 3;

如果没有辅助变量,你也可以这样做:

NSInteger quotient = *arrayCount / 3;
NSInteger rest = *arrayCount % 3;

仅删除参考操作人*>。 不是要点:

NSInteger quotient = arrayCount / 3;
NSInteger rest = arrayCount % 3;
问题回答

暂无回答




相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签