我想得到设备上设置的十进制符号.直到现在我才使用这种方法:
NSString *decimalSymbol;
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
[f setMinimumFractionDigits:2];
[f setMaximumFractionDigits:2];
[f setGroupingSeparator:@" "];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMinimumFractionDigits:2];
[formatter setMaximumFractionDigits:2];
[formatter setGroupingSeparator:@" "];
NSRange range = {1,1};
decimalSymbol = [[formatter stringFromNumber:[f numberFromString:[@"" stringByAppendingFormat:@"%.02f", 1.0f]]] substringWithRange:range];
[formatter release];
[f release];
Run Code Online (Sandbox Code Playgroud)
直到现在,当我在另一台设备(4.3)上进行测试时,它工作正常 - null返回.可能是什么问题呢?
是否有另一种方法来检索小数符号?
后期编辑:
我可以使用:
decimalSymbol = [[@"" stringByAppendingFormat:@"%.02f", 1.0f] substringWithRange:range];
Run Code Online (Sandbox Code Playgroud)
但为什么另一种方式它不能在这个特定的设备上工作?
我的应用程序中存在问题.我试图找到用户的位置以达到最佳精确度,以确定他们的邮政编码.目前我有一个按钮,按下后,启动一个名为的方法locateMe.
-(IBAction)locateMe; {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
然后我实施了 didUpdateToLocation:
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation; {
NSLog(@"Found location! %f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
我之前做过更复杂的事情,didUpdateToLocation但是当我测试了一些东西时,我意识到它发现的第一个位置至少不准确.所以,我把NSLog电话放在那里,它给了我一个类似于下面的输出......
Found location! 39.594093,-98.614834
Found location! 39.601372,-98.592171
Found location! 39.601372,-98.592171
Found location! 39.611444,-98.538196
Found location! 39.611444,-98.538196
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它首先给了我一个不正确的值,这在我的应用程序中引起了问题,因为它没有给出正确的位置.
所以,这是我的问题.有什么办法我可以等待位置经理找到最准确的位置吗?
提前致谢!
编辑:我想要这样的东西:
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
}
Run Code Online (Sandbox Code Playgroud)
但它永远不会被召唤!
我在我的应用程序中创建了主窗口以进行这些设置:
[self setLevel:kCGDesktopWindowLevel + 1];
[self setCollectionBehavior:
(NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorIgnoresCycle)];
Run Code Online (Sandbox Code Playgroud)
这是一个非常自定义的窗口,可以在桌面上方浮动.
另外,它是一个菜单栏应用程序(LSUIElement).
好吧,所以如果出现问题,我需要显示警报.我是这样做的:
NSAlert *alert = [NSAlert alertWithMessageText:@""
defaultButton:@""
alternateButton:@""
otherButton:@""
informativeTextWithFormat:@""];
[alert runModal];
Run Code Online (Sandbox Code Playgroud)
我当然填写了按钮和其他文字.
这是我的问题:当我的应用程序当前不是关键应用程序,并且弹出此警报时,它不是关键窗口.像这样:

看看窗口是如何选择的?有没有办法改变我的整个应用程序窗口级别?谢谢!
我正在尝试在使用IE6的用户使用我的网站时显示警报.我在想这样的事情会起作用:
<!--[if IE 6]>
<script language="Javascript">
alert ("The year 2004 just called - they want their browser back!")
</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
我测试了这个,但是我没有可以使用ATM的Windows盒子.这是正确的方法吗?
我正在开发一个Cocoa应用程序,它具有某些我希望保护但仍然可以显示的资源(图像).通常只需将它们放在资源文件夹中,但存储在那里可以很容易地抓取和使用它们.有没有办法隐藏这些图像,但仍然可以在应用程序中访问它们?
我有CALayer阴影的问题.以下是我的观点:
UIImage *screenshot = [SomeClass getScreenshot:mainView.view]; //full screen snap
CGFloat scale = [SomeClass getScreenScale]; // 1 or 2 for retina
CGFloat width = mainView.view.frame.size.width;
CGRect r1 = CGRectMake(0, 0, width*scale, 300*scale);
CGRect u1 = CGRectMake(0, 0, width, 300);
CGImageRef ref1 = CGImageCreateWithImageInRect([screenshot CGImage], r1);
l1 = [[UIButton alloc] initWithFrame:u1];
UIImage *img1 = [UIImage imageWithCGImage:ref1];
[l1 setBackgroundImage:img1 forState:UIControlStateNormal];
[l1 setAdjustsImageWhenHighlighted:NO];
CGImageRelease(ref1);
[mainView.view addSubview:l1];
Run Code Online (Sandbox Code Playgroud)
好的,这样就可以了.添加的图像是视网膜分辨率.但是,只要我向图层添加阴影,它就会跳转到标准分辨率,使按钮显得模糊.
l1.layer.shadowOffset = CGSizeMake(0, 0);
l1.layer.shadowRadius = 20;
l1.layer.shadowColor = [UIColor blackColor].CGColor;
l1.layer.shadowOpacity = 0.8f;
l1.layer.shouldRasterize = YES; …Run Code Online (Sandbox Code Playgroud) 看看Droplr iPhone应用程序:

请注意UIBarButtonItems 如何触摸屏幕/导航栏的右侧,左侧,顶部和底部?
我怎样才能达到类似的效果?以下是我如何制作示例UIBarButton并将其设置为正确的项目:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *bb = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease];
[self.navigationItem setRightBarButtonItem:bb animated:YES];
Run Code Online (Sandbox Code Playgroud)
但是,它没有正确对齐,并且从顶部和底部有相当多的余量.我的图像尺寸是正确的(44像素),它看起来像缩小它以适应各种框架.
那么,我该怎么做呢?
编辑:哎呀,顶部/底部间距是我的错.但是,我无法弄清楚如何将条形按钮与左/右侧齐平.这就是我的意思:(抱歉丑陋的按钮,这只是一个测试)

我尝试设置图像插入,但似乎没有做任何事情.
我正在尝试在我的应用程序中创建新用户.我知道可以使用dscl和NSTask.But是否有人知道如何使用任何Cocoa API,或者使用objective-c编程?在代码中,不使用bash命令,就像这里一样
sudo niutil -create / /users/newuser
sudo niutil -createprop / /users/newuser uid 502
sudo niutil -createprop / /users/newuser gid 502
sudo niutil -createprop / /users/newuser realname "Longer Name"
sudo niutil -createprop / /users/newuser home "/Users/newuser "
sudo niutil -createprop / /users/newuser shell "/bin/tcsh"
sudo niutil -createprop / /users/sharedDir shell "Public"
sudo niutil -createprop / /users/newuser passwd "*"
sudo passwd newuser
sudo ditto /System/Library/User\ Template/English.lproj /Users/newuser
sudo chown -R newuser :group /Users/newuser
Run Code Online (Sandbox Code Playgroud)
我被告知可以使用Open Directory Framework,但找不到有用的文档.谢谢.
我在10.8的一个应用程序中使用XPC.它具有为导出的接口和远程接口定义的协议的标准设置.我遇到的问题是在导出的界面上使用我的一个方法.
我有一个模型类,让我们调用它Foo.该类使用安全编码方法正确地符合NSSecureCoding,实现+supportsSecureCoding和编码/解码内部属性.通过我的导出接口上只涉及单个实例的方法传递此对象时,它可以正常工作.
当我想通过这些对象的集合,或将出现问题NSArray的Foo对象.以下是导出界面上签名的示例:
- (void)grabSomethingWithCompletion:(void (^)(NSArray *foos))completion;
Run Code Online (Sandbox Code Playgroud)
我已将该Foo课程列入白名单,如文档中所述:
NSSet *classes = [NSSet setWithObject:Foo.class];
[exportedInterface setClasses:classes forSelector:@selector(grabSomethingWithCompletion:) argumentIndex:0 ofReply:YES];
Run Code Online (Sandbox Code Playgroud)
现在这应该使得这个数组可以安全地复制到整个过程中并在另一侧进行解码.不幸的是,这似乎没有按预期工作.
在导出的协议上调用方法时,我收到一个异常:
警告:在解码收到的回复消息'grabSomethingWithCompletion:',丢弃传入消息和调用失败块时捕获到异常.
异常:解码调用参数1时发生异常:返回值:{v} void target:{@?} 0x0(块)参数1:{@} 0x0
例外:关键'NS.objects'的值是意外的类'Foo'.允许的类是'{(NSNumber,NSArray,NSDictionary,NSString,NSDate,NSData)}'.
这几乎看起来它甚至没有注册我之前执行的白名单.有什么想法吗?
iphone ×5
objective-c ×5
cocoa-touch ×4
cocoa ×3
macos ×3
calayer ×1
html ×1
ios ×1
javascript ×1
nsalert ×1
uiwebview ×1
xpc ×1