Tag: ios

添加cocoapodstesting目标呢?

我有安装了testing和cocoapods的默认项目模板( pod install )。 豆荚的主要目标工作正常,但是当我尝试导入testing中的东西时,我得到了类似的东西 Time.m:11:9: 'NSDate-Utilities.h' file not found 这是否意味着我应该将pod目录添加到testing目标中的标题searchpath中? 这可以通过cocoapods CLI自动以某种方式完成吗? 通过build议的链接的这个问题有错误的答案,直到昨天。

如何从当前的graphics上下文创build一个UIImage?

我想从当前的graphics上下文创build一个UIImage对象。 更具体地说,我的用例是一个用户可以画线的视图。 他们可能会逐渐绘制。 完成后,我想创build一个UIImage来表示他们的绘图。 下面是drawRect:现在看起来对我来说: – (void)drawRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSaveGState(c); CGContextSetStrokeColorWithColor(c, [UIColor blackColor].CGColor); CGContextSetLineWidth(c,1.5f); for(CFIndex i = 0; i < CFArrayGetCount(_pathArray); i++) { CGPathRef path = CFArrayGetValueAtIndex(_pathArray, i); CGContextAddPath(c, path); } CGContextStrokePath(c); CGContextRestoreGState(c); } …其中_pathArray是CFArrayReftypes的,并且每次调用touchesEnded:时都会被填充。 另外请注意,drawRect:可能会在用户绘制时被调用多次。 当用户完成后,我想创build一个代表graphics上下文的UIImage对象。 任何build议如何做到这一点?

无法在Swift中的Storyboard中加载UIViewController XIB文件

我读过使用XCode storyboard来实例化视图控制器,它使用XIB的devise,但我有麻烦使这个工作在Swift(使用Xcode 6 Beta 6)。 我想知道如果我做错了什么,或者如果这个function不可用? 我创build了一个简单的存储库, https://github.com/jer-k/StoryboardTesting-Swift ,展示了上面的方法。 我设法通过添加并覆盖到init来解决问题 required init(coder aDecoder: NSCoder) { super.init(nibName: "TestViewController", bundle: NSBundle.mainBundle()) } 但我想知道是否还有可能让故事板为我处理。 创build一个超类让所有的UIViewControllersinheritance上面的代码并不是世界上最麻烦的事情,但我只是好奇于此。

从swift文件目录中获取图像

说我正在使用这个代码来保存图像到文件directroy let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory let nsUserDomainMask = NSSearchPathDomainMask.UserDomainMask if let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true) { if paths.count > 0 { if let dirPath = paths[0] as? String { let readPath = dirPath.stringByAppendingPathComponent("Image.png") let image = UIImage(named: readPath) let writePath = dirPath.stringByAppendingPathComponent("Image2.png") UIImagePNGRepresentation(image).writeToFile(writePath, atomically: true) } } } 我将如何回顾它? 请记住,在iOS8中,确切的path经常变化

在iOS中生成范围内的随机数?

我试图得到一个随机数发生器在iPhone上工作。 有两个文本字段标签和一个button。 在一个文本框中input最小数量,然后在下一个文本框中input最大数量 点击button将显示UILabel中的随机数。 我曾经这样做过一次,也无法想象今天的生活。 任何代码或我可以访问的地方find这个将是太棒了。 谢谢

如何捕捉所有iOS推送通知与不同的用户操作,包括点击应用程序图标

根据苹果指南: “通过提示通知,用户点击提醒的操作button或点击(或点击)应用程序图标,如果点击操作button(在运行iOS的设备上),系统启动应用程序和应用程序调用其委托的应用程序:didFinishLaunchingWithOptions:方法(如果已实现);它传入通知有效内容(用于远程通知)或本地通知对象(用于本地通知)。 如果在运行iOS的设备上点击应用程序图标,应用程序将调用相同的方法,但不提供有关通知的信息。 如果在运行Mac OS X的计算机上单击应用程序图标,应用程序将调用代理的applicationDidFinishLaunching:方法,在该方法中代理可以获取远程通知有效内容。 我的问题是,假设用户得到了来自提供商的3-4推送通知,并且所有都存储在苹果的通知中心。 如果用户点击通知提醒,他/她可以很容易地在应用程序中获取通知数据。 但是,如果用户点击iPhone上的应用程序图标,如何获取所有以前的通知相关的所有数据。 提前致谢!

在iOS中使用Javascript复制到剪贴板

我正在使用此function将URL复制到剪贴板: function CopyUrl($this){ var querySelector = $this.next().attr("id"); var emailLink = document.querySelector("#"+querySelector); var range = document.createRange(); range.selectNode(emailLink); window.getSelection().addRange(range); try { // Now that we've selected the anchor text, execute the copy command var successful = document.execCommand('copy', false, null); var msg = successful ? 'successful' : 'unsuccessful'; if(true){ $this.addClass("copied").html("Copied"); } } catch(err) { console.log('Oops, unable to copy'); […]

ScrollView手势识别器吃所有的触摸事件

我有一个UIScrollView ,我添加了一个轻击手势识别器来显示/隐藏一些UI覆盖使用: UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [scrollView addGestureRecognizer:singleTap]; 和: – (void)handleTap:(UITapGestureRecognizer *)sender { // report click to UI changer } 我在UIScrollView的底部添加了一个简单的表格视图 。 一切工作正常(水平和垂直滚动),但问题是,只有手势识别器(上面),而不是简单的表视图识别轻敲。 如果我删除注册手势监听器的行,一切工作正常,表视图通知自己点击。 这就好像手势识别器function在桌面视图上“吃”了轻敲事件,并且不会向下传播它们。 任何帮助表示赞赏

iPhone获得所有SSID列表没有私人图书馆

是否有可能获得所有可用的SSID 列表 ,而不使用私人图书馆? 我读了没有私人图书馆得到SSID https://stackoverflow.com/a/6341893/346255 https://developer.apple.com/library/ios/#documentation/SystemConfiguration/Reference/CaptiveNetworkRef/Reference/reference.html 但似乎没有一个解决scheme来获得所有可用networking的列表,而无需使用私人图书馆或连接到所有可用的networking(什么是荒谬的…) 所以基本上我错过了一些东西,还是没有解决scheme?

将子视图控制器的视图添加到父视图控制器的子视图中

我想添加一个tableViewController作为一个containerViewController的子视图控制器(如下所示)。 根据苹果公司的视图控制器编程指南,我可以通过在我的containerViewController里面的以下几行代码来实现: [self addChildViewController:tableViewController]; [self.view addSubview:tableViewController.view]; [tableViewController didMoveToParentViewController:self]; 事实上,这工作正常。 现在的问题是,我不想添加tableViewController的视图作为containerViewController的根视图的子视图。 相反,我想添加它作为containerView的子视图(见图),它本身是containerViewController的根视图的子视图。 所以我改变了上面的代码如下: [self addChildViewController:tableViewController]; [self.contentView addSubview:tableViewController.view]; [tableViewController didMoveToParentViewController:self]; 现在,当我启动应用程序,它立即崩溃,这个错误: 终止应用程序由于未捕获的exception'UIViewControllerHierarchyInconsistency',原因:'子视图控制器:应该有父视图控制器:但实际的父母是:' 这里有什么问题? 是不是可以添加一个childViewController的视图到其containerViewController的特定子视图? 或者我怎么能实现这个没有在视图控制器层次结构中的错误?