Tag: cocoa

在debugging模式下启用和禁用NSLog

我想在debugging时启用NSLog,否则禁用它。 一个非常简单的事情是: #ifdef DEBUG NSLog(@"My log"); #endif 但是,所有这#ifdef和#endif是borring … :(所以我尝试其他的东西:( .pch是放好它的好地方) #ifdef DEBUG # define NSLog(text) NSLog(text); #else # define NSLog(text) #endif 这项工作非常好(不recursion)。 但问题是,NSLog有无限的参数。 void NSLog(NSString *format, …) 我如何解决这个工作在预处理器模式? – 编辑 – 这段代码使你的NSLog更好: #ifdef DEBUG #define NSLog(FORMAT, …) fprintf(stderr,"%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); #else #define NSLog(…) #endif

如何获取设备的宽度和高度?

在Objective-C中,我们可以通过使用以下代码来获取设备宽度和高度: CGRect sizeRect = [UIScreen mainScreen].applicationFrame float width = sizeRect.size.width float height = sizeRect.size.height 在Swift中如何做到这一点?

将NSData字节转换为NSString?

我正在尝试使用BEncoding ObjC类来解码.torrent文件。 NSData *rawdata = [NSData dataWithContentsOfFile:@"/path/to/the.torrent"]; NSData *torrent = [BEncoding objectFromEncodedData:rawdata]; 当我NSLog torrent我得到以下内容: { announce = <68747470 3a2f2f74 6f727265 6e742e75 62756e74 752e636f 6d3a3639 36392f61 6e6e6f75 6e6365>; comment = <5562756e 74752043 44207265 6c656173 65732e75 62756e74 752e636f 6d>; "creation date" = 1225365524; info = { length = 732766208; name = <7562756e 74752d38 2e31302d 6465736b 746f702d 69333836 […]

如何在iPhone上显示更长的启animation面?

如何在iPhone上显示比默认时间更长的启animation面?

NSDateFormatter setDateFormat的序号月份后缀选项

什么setDateFormat选项NSDateFormatter我用来获得一个月份的序号后缀? 例如下面的代码片段产生: 8月15日星期六下午3:11 我必须改变什么来获得: 8月15 日星期六下午3:11 NSDate *date = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setDateFormat:@"h:mm a EEEE MMMM d"]; NSString *dateString = [dateFormatter stringFromDate:date]; NSLog(@"%@", dateString); 在PHP中,我会用上面的情况: <?php echo date('h:m A l F jS') ?> 是否有一个NSDateFormatter相当于PHP格式string中的S选项?

Xcode成功构build我的目标,但不运行该产品

我已经在Mac OS X Lion上安装了Xcode 4.2.1。 当我创build一个新的(Mac OS X的cocoa)项目,我点击“运行”,Xcode说构build成功,但不运行该项目。 没有错误,但没有应用程序。 当我在另一台Mac上完成同样的事情(但安装了OS X Snow Leopard和Xcode 4.0.1)时,所创build的应用程序开始在扩展坞中popup,并显示一个空的窗口,就像我所期望的那样。 当我查看控制台时,似乎没有什么奇怪的事情发生。 我尝试重新安装Xcode,删除与Xcode有关的所有东西,但仍然没有运气。 任何人有一个想法可能是什么问题? (我尝试运行一个曾经工作的现有项目,但是也没有显示任何东西)

警告:试图在已经呈现的MainTableViewController上呈现ModalTableViewController(null)

我有一个popover的问题。 如果我点击一个单元格,我会加载一个popover来select更多的细节。 一切工作正常,但是当我再次按下我的细胞时,我收到每一次以下消息: 警告:尝试在MainTableViewController上呈现ModalTableViewController …已经呈现(null) 如果我点击另一个单元格,我不会得到这个警告。 只有当再次点击同一行。 我尝试了很多东西,但是我无法解决这个问题。 我加载我的popover像这样: var popover: UIPopoverController! var popoverContent: ModalTableViewController! 并在我的细胞水龙头: popoverContent = self.storyboard.instantiateViewControllerWithIdentifier("ModalTableViewController") as ModalTableViewController popoverContent.selectedQuestionID = indexPath!.row popover = UIPopoverController(contentViewController: popoverContent) popover.delegate = self popover.presentPopoverFromRect(currentCell.LabelCellTitle.frame, inView: currentCell.LabelCellTitle.superview, permittedArrowDirections: UIPopoverArrowDirection.Left, animated: true) 并解雇 func popoverControllerDidDismissPopover(popoverController: UIPopoverController!) { popover.dismissPopoverAnimated(false) // just to check self.popover = nil self.popoverContent = nil } […]

在主线程上发布NSNotification

我发现下面的代码片断允许NSNotification从任何后台线程发布到主线程上。 我想知道这是否是一个安全和可接受的做法? dispatch_async(dispatch_get_main_queue(),^{ [[NSNotificationCenter defaultCenter] postNotificationName:@"ImageRetrieved" object:nil userInfo:imageDict]; });

更改“返回”键盘button的文本

如何将“返回”button的标准文本更改为其他内容? 我希望它是“添加”。

视网膜显示和

我需要从服务器下载的原始数据初始化图像,根据iPhone客户端的types提供正确的图像大小。 我知道我应该在640×960显示器上将scale值设置为2.0,但是这是只读属性,在使用initWithData时不能在init中设置。 有任何想法吗?