在Swift中从另一个ViewController访问variables

我有以下ViewController : class PageContentViewController: UIViewController { var pageIndex: Int } 我如何访问另一个ViewController的pageIndex ? 我需要在这个函数中访问pageIndex : func pageViewController(pageViewController: UIPageViewController!, viewControllerBeforeViewController viewController: UIViewController!) -> UIViewController! { //var index: Int //index = ? NSUInteger index = ((PageContentViewController*) viewController).pageIndex; // in Swift? if ((index == 0) || (index == NSNotFound)) { return nil; } index–; return [self viewControllerAtIndex:index]; // in […]

Swift正则expression式:一个string匹配模式?

在Swift中,查看一个string是否匹配模式的简单方法是什么? 伪代码示例: if string matches pattern … if string =~ pattern … (我已经阅读了Swift文档,并没有看到正则expression式的能力,我已经阅读了关于添加一个新的=~运算符,这是一个好主意,但比我想要的更复杂,因为这是一个教学项目。尝试rangeOfString但得到错误:'string'没有成员'rangeOfString'。我正在寻找一个Swift解决scheme,即不键入NSRegularExpression。我不需要做任何事情的匹配结果数据。

自定义Push Segue删除故事板中的导航栏和标签栏

我在定义Segue中定义了以下内容,让我们把它称为SegueX: @interface SegueX : UIStoryboardSegue @end @implementation SegueX – (void)perform { CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; [[self.sourceViewController navigationController].view.layer addAnimation:transition forKey:kCATransition]; [[self.sourceViewController navigationController] pushViewController:[self destinationViewController] animated:NO]; } @end 在我的故事板中,我刚刚将一个标准的Push segue改成了SegueX。 出于某种原因,这将删除我的导航栏和标签栏。 而且,在定制的segue之后,在故事板中定义的所有UIBarButtonItems都在运行时隐藏。 我该如何解决? 我希望它不是这样的… 在更改为自定义赛格之前 改成自定义赛格后 保存到Main.storyboard <?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="aUj-3O-DdX"> […]

找不到Pods.modulemap – 查找错误的目录

我试图让CocoaPods在Swift项目中工作,但这是我第一次。 我的Podfile是 source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! pod 'Alamofire', '~> 1.2' pod 'SwiftyJSON', '~> 2.2.0' 我运行pod install但是构build它给了我这个错误: Error: unable to read module map contents from 'Target Support Files/Pods/Pods.modulemap': Error Domain=NSCocoaErrorDomain Code=260 "The file “Pods.modulemap” couldn't be opened because there is no such file." UserInfo=0x7fac488d5af0 {NSFilePath=/Users/jt/tmp-ios/my-template/Pods/Target Support Files/Pods/Pods.modulemap, NSUnderlyingError=0x7fac457f0e90 "The operation couldn't be completed. No […]

iOS应用更新通知

iOS应用更新机制如何工作? 如何告诉用户Appstore上的应用程序已更新?是否必须在代码中编写function以显示更新popup窗口,或者是由Appstore处理以向用户显示该应用程序已更新的通知。 有没有为此提供的苹果文件?

为什么不能在drawRect中更改UIView背景颜色?

从理论上讲,您可以通过以下方式轻松设置背景色 self.backgroundColor = [UIColor redColor]; 在drawRect中,但这没有任何作用。 您可以更改视图的大小,边框,子视图等,但不能改变背景颜色。 类似的SO查询build议添加一个子视图或更改initWithFrame或initWithCoder初始化消息中的backgroundColor。 我的问题是为什么在其他特性可以改变的时候不能在drawRect中工作? 更改视图的图层backgroundColor也没有什么,也许出于同样的原因。 视图的backgroundColor和它的图层的backgroundColor之间有什么关系,因为它们不一样?

iOS8dynamic框架 – > CodeSign错误:SDK'iOS 8.3'中的产品types'框架'需要代码签名

我正在使用我自己构build的iOS8dynamic框架,并在我的iOS应用程序中进行链接。 它在模拟器和设备上工作正常,但是当试图为它发布Release版本时,我一直得到这个错误: 代码签名错误:未find匹配的configurationconfiguration文件:没有有效的configurationconfiguration文件允许指定的权利:com.apple.developer.ubiquity-kvstore-identifier,keychain-access-groups,com.apple.developer.icloud-container-identifiers ,com.apple.developer.icloud-services,com.apple.security.application-groups,com.apple.developer.ubiquity-container-identifiers。 CodeSign错误:SDK'iOS 8.3'中产品types'Framework'需要代码签名 在应用程序目标 – >构build阶段 – >embedded框架 – >框架链接在那里,并选中“复制代码签名”checkbox。 在框架目标 – >构build设置 – >我已经设置configuration文件为“自动”,并且对于代码标识标识,在Release下,我使用的是“iOS分发” 我有3个不同的应用程序目标需要build立这个框架。 我很困惑: 该框架是否需要在Developer Center中注册自己的AppID? 该框架是否需要它自己的Provisioning Profile? 框架可以使用iOS应用程序目标中相同的权利文件吗? 谢谢。

如何取消用addOperationWithBlock创build的操作?

我正在使用NSOperationQueue的addOperationWithBlock。 从该区块内,我该如何检查是否应该取消操作? 或者访问任何NSOperation属性/方法? [myOperationQueue addOperationWithBlock: ^{ while ( /* long running loop */ ) { // how to determine here if I need to cancel? // for that matter, access any NSOperation properties/methods? } }]; 是更好的方式来做到这一点使用NSBlockOperation?

当从不同的线程使用NSDateFormatter崩溃

我们不断得到NSDateFormatter一个随机,奇怪的崩溃。 相关的堆栈跟踪是: Program received signal: “EXC_BAD_ACCESS”. #0 0x00000005 in ?? () #1 0x0213e3c3 in udat_parse () #2 0x01d4e1ca in CFDateFormatterGetAbsoluteTimeFromString () #3 0x01d4e225 in CFDateFormatterCreateDateFromString () #4 0x003e2608 in getObjectValue () #5 0x003e2921 in -[NSDateFormatter getObjectValue:forString:errorDescription:] () #6 0x003e21cd in -[NSDateFormatter dateFromString:] () date格式化程序仍然在内存中(即不释放或损坏)。 我唯一能想到的是在崩溃时的string不符合格式,但我怀疑这会使格式化程序完全崩溃。 (事先检查格式是不重要的)。 有什么想法吗?

我如何使用UIActivityItemProvider发送带有UIActivityViewController附件的电子邮件?

我想通过电子邮件附件使用UIActivityItemProvider从我的应用程序共享文件。 我还需要填写电子邮件的主题行,并指定附件的名称与设备上存储的文件的名称不同。 这是我正在使用的代码。 问题是电子邮件中缺less附件。 @interface ItemProvider:UIActivityItemProvider @property (nonatomic, strong) NSURL *filepath; @property (nonatomic, strong) NSString *emailBody; @property (nonatomic, strong) NSString *emailSubject; @end @implementation ItemProvider – (id)initWithPlaceholderItem:(id)placeholderItem { //Initializes and returns a provider object with the specified placeholder data return [super initWithPlaceholderItem:placeholderItem]; } – (id)item { //Generates and returns the actual data object return [NSDictionary dictionary]; […]