2011-09-24 69 views
0

所以我需要用变量除以数字。 我该怎么做? 我知道DIV和MOD的C函数,但不知道如何在Objective-C/cocoa-touch中使用它们。这是我的代码的一个例子。Objective-C中划分变量

// 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 

当我尝试使用/或%我得到的错误 “无效操作数为二进制表达式('NSUInteger和INT) 感谢您的帮助

+0

Xcod e是一种IDE而不是语言。 – Nick

回答

5

首先,arrayCount真的应该是一个指针?

无论如何,如果arrayCount是一个指针,你只需要取消对它的引用...

NSInteger arrayCountValue = *arrayCount; 

...并使用运营商/(除法)和%(用于获取模块):

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

你可以不用辅助变量太多:

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

而就如果arrayCount不是指针,请移除解除引用运算符*

NSInteger quotient = arrayCount/3; 
NSInteger rest = arrayCount % 3; 
+0

谢谢,这就是我所需要的 – Thermo