在iOS 4.1上成功从iPhone相机获取图片后,您可以使用该密钥
@"UIImagePickerControllerMediaMetadata"
Run Code Online (Sandbox Code Playgroud)
返回有关图片的信息.该词典中的一个关键是
@"Orientation"
Run Code Online (Sandbox Code Playgroud)
从我的实验来看,肖像和颠倒分别是6和8,景观是1和3.看看这段代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSDictionary *metaData = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
id orientation = [metaData objectForKey:@"Orientation"];
NSLog(@"Class: %@",[orientation class]);
Run Code Online (Sandbox Code Playgroud)
NSLog说"Class:NSCFNumber"
我需要比较这个对象的值来确定如何继续.横向是1或3,纵向是6或8.我不确定要键入方向或调用什么.NSNumber和NSInteger总是告诉我,我正在使用没有强制转换的指针制作整数.
谢谢你的时间!
我不明白NSNumberFormatterPercentStyle是如何工作的!
例:
NSNumber *number = [NSNumber numberWithFloat:90.5];
NSNumberFormatter *percentageFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[percentageFormatter setNumberStyle:NSNumberFormatterPercentStyle];
NSString *strNumber = [percentageFormatter stringFromNumber:numbericString];
NSLog (strNumber); // Output: 9,050%
Run Code Online (Sandbox Code Playgroud)
我只想表现出"90.5%"(尊重NSLocal).什么是NSNumberFormatterPercentStyle使用90.5,为什么?而且,我怎样才能得到我想要的结果!?
我的应用程序中有一个JSON解析器,我将值加载到detailDataSourceDict变量中.当我尝试获取数组的valueForKey并尝试将其与0进行比较时,它永远不会...
这是我的代码:
if (indexPath.row == 1) {
NSNumber *rating = [detailDataSourceDict valueForKey:@"rating"];
NSLog(@"Rating: %@",rating);
if (rating == 0) {
cell.detailTextLabel.text = @"This sheet has not yet been rated.";
}
else {
cell.detailTextLabel.text = [NSString stringWithFormat:@"This sheet has a %@ star rating.",rating];
}
cell.textLabel.text = @"Rating";
}
Run Code Online (Sandbox Code Playgroud)
我在我的JSON Feed中看到"评级":"0",但是当评级为0时,它显示"此表格有0星评级."而不是"此表尚未评级".
有什么建议?谢谢.
所以这个问题让我感到困惑太久了.我有UIAlertView一个textField在里面,而我需要的价值textField为NSNumber.但我尝试的一切都给了我随机的数字串.任何帮助将非常感谢.
int i = [[alertView textFieldAtIndex:0].text intValue];
NSNumber *number = [NSNumber numberWithInt:[[alertView textFieldAtIndex:0].text integerValue]];
int number = [[dict objectForKey:@"integer"] intValue];
NSLog(@"text = %@", [alertView textFieldAtIndex:0].text);
NSString *alertText = [alertView textFieldAtIndex:0].text;
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterNoStyle];
NSNumber * myNumber = [f numberFromString:[alertView textFieldAtIndex:0].text];
NSNumber *number = @([alertText intValue]);
NSString *string = @"54";
NSNumber *number = @([string intValue]);
NSLog(@"here we are: %i", number);
Run Code Online (Sandbox Code Playgroud) 我喜欢使用@"string"符号在Objective C中快速处理字符串文字.有没有办法让NSNumbers 获得类似的行为?我更多地处理数字,而且[NSNumber numberWithWhatever:]到处都有电话这么乏味.即使创建一个宏也可行,但我对如何最好地做到这一点的知识是有限的.
如何检查NSNumber对象是否为空?
好的很容易:
NSNumber *myNumber;
if (myNumber == nil)
doSomething
Run Code Online (Sandbox Code Playgroud)
但是如果对象已经创建,但由于分配失败而没有值,我该如何检查?用这样的东西?
if ([myNumber intValue]==0)
doSomething
Run Code Online (Sandbox Code Playgroud)
是否有一种通用的方法来测试空虚上的对象,例如NSString可用(参见这篇文章))?
例1
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@"" forKey:@"emptyValue"];
NSNumber *emptyNumber = [dict objectForKey:@"emptyValue"];
Run Code Online (Sandbox Code Playgroud)
哪个值emptyNumber包含?我该怎么检查emptyNumber为空?
例2
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@"" forKey:@"emptyValue"];
NSString *myString = [dict objectForKey:@"emptyValue"];
if (myString == nil || [myString length] == 0)
// got an empty value
NSNumber *emptyNumber=nil;
Run Code Online (Sandbox Code Playgroud)
如果我之后使用它会发生什么 emptyNumber设置为nil?
[emptyNumber intValue]
Run Code Online (Sandbox Code Playgroud)
我得到零吗?
例3
NSMutableDictionary *dict = [[NSMutableDictionary alloc] …Run Code Online (Sandbox Code Playgroud) 我想通过本主题中与NSStrings相同的样式制作一些NSNumber常量.也就是说,我正在创建单独的constants.h/.m文件并将它们导入需要访问它们的类中.
我有一个简单的问题(我认为):我正在尝试将NSNumber与int进行比较,看看它是0还是1.这是代码:
id i = [dictionary objectForKey:@"error"]; //class = NSCFNumber
NSLog(@"%@ == 0 -> %@", i, i == 0);
NSLog(@"%@ == 0 -> %@", i, [i compare:[NSNumber numberWithBool:NO]]);
Run Code Online (Sandbox Code Playgroud)
我试过这个方法,但结果是null:
2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null)
2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null)
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗?
有一个坐标对象有三个变量纬度(NSNumber),经度(NSNumber)和时间(NSDate),为了检查我的模拟器上的程序,我给了下面的代码
[coordinate setLatitude:[NSNumber numberWithDouble:23.234223]];
[coordinate setLongitude:[NSNumber numberWithDouble:73.234323]];
Run Code Online (Sandbox Code Playgroud)
但是当我NSLog coordinate.latitude和coordinate.longitude时,它会显示0.00000
NSLog(@"cordlat : %f",coordinate.latitude);
NSLog(@"cordlong : %f",coordinate.longitude);
Run Code Online (Sandbox Code Playgroud)
可能是什么问题???
如何在objective-c中设置NSNumber变量的值(不创建新对象)?
背景
nsnumber ×10
objective-c ×7
iphone ×6
ios ×4
cocoa-touch ×1
compare ×1
constants ×1
int ×1
json ×1
macros ×1
nsstring ×1
percentage ×1