草庐IT

ios - 用于 int 值的 StringWithFormat 有一个问题

我目前有一个自定义格式并显示在标签中的int值。int值始终是一个5位数字,我在十分位和百位之间用+符号显示它。如果number=12345,displayNumber=123+45。ViewController.minthigh=number/100;intlow=number-(high*100);NSString*displayNumber=[NSStringstringWithFormat:@"%d+%d",high,low];我的问题是数字的十分之一为零。如果number=12304,displayNumber将显示为123+4,而我希望它显示为123+04。我试过对low

ios - 键值观察的新手;为什么我无法在我的 AppDelegate 中监控 int 的值?

我的Objective-C++AppDelegate中有一个名为stepsCompleted的公共(public)变量,所以我在TableViewController中使用[AppDelegateinstance]->stepsCompleted访问它。我希望我的TableViewController在该变量的值发生变化时告诉我,所以我在我知道正在调用的initWithCoder:方法中执行以下操作:[selfaddObserver:selfforKeyPath:@"[AppDelegateinstance]->stepsCompleted"options:0context:NULL]

objective-c - 如何更改 block 中的int值?

如何在block中更改int值,我有这个:__blocklonglongsize=-1;ALAssetsLibraryAssetForURLResultBlockresultblock=^(ALAsset*myasset){ALAssetRepresentation*rep=[myassetdefaultRepresentation];size=[repsize];//hereshowednormalvalueNSLog(@"neededsize:%lld",size);};ALAssetsLibrary*assetslibrary=[[[ALAssetsLibraryalloc]in

ios - 将 int 转换为 *NSInteger

使用时NSInteger*myInteger=45;我收到警告消息IncompatibleIntegertopointerconversionsending'NSInteger'(aka'int')toparameteroftype'NSInteger*'(aka'int*')我已阅读另一篇具有相同警告的帖子,但没有找到合适的解决方案。 最佳答案 NSInteger不是NSObject的子类,它是一个原始类型。将您的代码更改为:NSIntegera=45;并且(当然)不要将变量命名为int

iphone - ios:如何将 NSString 转换为 int64_t?

我想将NSString转换为int64_t,然后使用以下命令将其打印出来:NSLog("%lld",i);现在我只能使用[strintegerValue]进行转换,这有时会使它打印出负数。 最佳答案 您可以使用[strlongLongValue]例如:int64_ti=[@"23570449442514"longLongValue]; 关于iphone-ios:如何将NSString转换为int64_t?,我们在StackOverflow上找到一个类似的问题:

ios - ObjectiveC 测试 int 是 long 还是 not/CGFloat 是 float 还是 double

Apple现在要求所有iOS代码都是32/64位二元的。这很好-除了他们的一些库不完全支持二元性。例如一个项目使用NSScanner,它支持“scanInteger”(正确)但不支持“scanCGFloat”——相反,您必须使用“scanFloat”或“scanDouble”(在方法名称中编码!)。更新:NSScanner是一个比我意识到的更糟糕的例子;它以指针作为参数。-(BOOL)scanFloat:(float*)result;-(BOOL)scanDouble:(double*)result;...呃。它影响了一大堆东西-另一个例子是math.h(类似地:floatvsdoub

ios - 尝试填充 NSMutableArray 但使用 arc 不允许将 int 隐式转换为 id

我只是想将一系列数字添加到NSMutableArray但出现错误:arc不允许将int隐式转换为idresultArray=[[NSMutableArrayalloc]init];for(inti=0;i我做错了什么? 最佳答案 NSArray或NSMutableArray只能保存对象,不能保存原始数据类型,例如int。因此,如果您想将它们添加到数组中,则必须将它们包装在NSNumber中。您可以执行以下操作:[resultArrayaddObject:@(i)];这相当于做:[resultArrayaddObject:[NSNum

android - 如何将 UIColor 转换为 Android 颜色(packed int)?

我在移动开发方面已经取得了相当大的进步,可以自己解决问题,但是我在解决这个问题时遇到了很多麻烦...我正在使用这个宏将Android颜色(packedint)转换为UIColor:#defineANDROID_COLOR(c)[UIColorcolorWithRed:((c>>16)&0xFF)/255.0green:((c>>8)&0xFF)/255.0blue:((c)&0xFF)/255.0alpha:((c>>24)&0xFF)/255.0]但是我还需要将UIColor转换为Android颜色。很感谢任何形式的帮助! 最佳答案

ios - 格式指定类型 'int' 但参数的类型为 'NSString *'

任何人:我想用一个宏来打印log,following,#defineisaObject(parameter)_Generic((parameter),id:YES,id__strong:YES,default:NO)#definekNSLog(parameter)do\{\BOOLis=isaObject((parameter));\if(is)\{\NSLog(@"----Yes:%@",parameter);\}\else\{\NSLog(@"----No:%d",parameter);\}\}while(NO)inti=99;NSString*s=@"abcd";kNSLog(i

objective-c - iOS - 文本字段到 int 变量

文本字段和整型变量的问题。我使用文本字段写一个数字,并在函数中使用这个数字。intchangeid=[idchoicetext];但是我必须重新输入,怎么办? 最佳答案 intchangeid=[idchoice.textintValue];完成。 关于objective-c-iOS-文本字段到int变量,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5754291/