在Swift中声明全局variables

我想创build一个可以在整个应用程序(AppDelegate,ViewController类,TableViewController类等)访问的自定义对象的全局数组。 我研究了一种方法来做到这一点,但还没有find答案。 我曾尝试使数组为公共范围,但我得到一个编译器警告说, Declaring public variable from internal class ,当我尝试访问它在不同的文件中,我得到一个错误,说Use of unresolved identifier 'arrayObjectives' 我将如何去使全局访问应用程序中的所有文件的数组,我将在哪里实例化该数组?

iphone – didSelectRowAtIndexPath:只在长按自定义单元格后被调用

我正在创build一个基于表视图的应用程序。 我为表创build了一个自定义表格单元格,其中包含2个标签,1个图像和1个button。 表视图数据源方法正常工作。 我为自定义单元格和视图控制器类使用xib,并将委托和数据源连接到文件的所有者。 但问题是,当我select表行,didSelectRowAtIndexPath没有得到消防。 如上所述,唯一的办法是按住电池约3-4秒钟。 有谁知道为什么会发生这种情况? 感谢任何指针… 这是我的表格视图的方法.. – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [finalAddonsArray count]; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; NewCustomCell *cell = (NewCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"NewCustomCell" owner:self options:nil]; cell=[nib objectAtIndex:0]; } […]

Xcode 7 UItesting:closures推送和位置警报

我遇到了Xcode 7 UItesting的问题。 该应用程序在用户login后显示两个警报, 请求位置警报和推送通知警报。 这些通知一个接一个地显示出来。 位置第一个出现。 我试图自动解雇他们开始我的testing。 为了做到这一点,我添加了两个UIInterruptionMonitor ,第一个是位置警报,第二个是通知推送警报。 addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in /* Dismiss Location Dialog */ if alert.collectionViews.buttons["Allow"].exists { alert.collectionViews.buttons["Allow"].tap() return true } return false } addUIInterruptionMonitorWithDescription("Push Dialog") { (alert) -> Bool in /* Dismiss Push Dialog */ if alert.collectionViews.buttons["OK"].exists { alert.collectionViews.buttons["OK"].tap() return true } return false } 但是只有位置被触发,推送通知UIInterruptionMonitor的处理程序永远不会被调用。 […]

以编程方式创buildUILabel

我知道这应该是非常简单的,但我一直在努力创build一个UILabel编程,并得到它的行为,我希望的方式。 我想要的只是能够创build一个标签,设置最大属性,高度,宽度和字体大小,然后让文本变小和/或只是截断文本,以适应长串文本。 假设我希望标签的文字宽度最大为380,最大高度为20,最大字体为12。 所以这就是我试图去创造这样一个标签: UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 0, 0)]; fromLabel.text = [self fromSender]; fromLabel.font = [UIFont fontWithName:ProximaNovaSemibold size:12]; //custom font fromLabel.numberOfLines = 1; fromLabel.baselineAdjustment = YES; fromLabel.adjustsFontSizeToFitWidth = YES; fromLabel.adjustsLetterSpacingToFitWidth = YES; fromLabel.size = [fromLabel.text sizeWithFont:fromLabel.font constrainedToSize:CGSizeMake(380, 20) lineBreakMode:NSLineBreakByTruncatingTail]; fromLabel.minimumScaleFactor = MIN_SCALE_FACTOR; fromLabel.clipsToBounds = YES; fromLabel.backgroundColor = [UIColor clearColor]; fromLabel.textColor = [UIColor […]

如何在UISegmentedControl中设置选定的段索引? (iPhone SDK)

我试图避免一个应用程序崩溃在这里…我有一个button,将从UISegmentedControl删除段。 如果按下该button,并且用户select了要移除的片段,则片段将被移除,并且不会突出显示select。 但是,当另一个button被推动,执行检索selectedSegmentIndex的操作时,应用程序崩溃。 简而言之:有什么办法可以强制在UISegmentedControl中select一个段吗? 编辑它看起来好像UISegmentedControl正在返回一个selectedSegmentIndex为-1时,没有select段…让我们看看我能做些什么从这里。

SKProductsRequest返回0个产品的原因是什么?

我试图设置IAP,但打电话来检索产品使用SKProductsRequest SKProductsResponse数组我的委托内有一个计数为0.这是我的清单: testing产品已添加到iTunes连接 产品的包ID与应用包ID相匹配(并且不使用通配符) SKProductRequest中设置的产品标识符与iTunes连接上创build的产品相匹配 自从在iTunes连接上创build产品后,我等了好几个小时 configuration文件启用IAP 遵循各种教程中的所有步骤,例如http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/等 从设备删除应用程序,重新启动Xcode,重build等。 关于为什么提取的产品数量为零的任何其他build议? 我不相信这会是一个编码问题,但是无论如何, … NSSet *productIdentifiers = [NSSet setWithObjects:@"redacted", nil]; self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; self.productsRequest.delegate = self; [self.productsRequest start]; … – (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSArray *products = response.products; NSLog(@"Product count: %d", [products count]); for (SKProduct *product in products) { NSLog(@"Product: %@ %@ %f", product.productIdentifier, […]

在Xcode 8和iOS 10中使用NSUserDefaults

NSUserDefaults不再是iOS 10 SDK中的一个类: let defaults = NSUserDefaults.standardUserDefaults() 这不能编译。 这个class级被删除了吗? (这是一个规范的问答对,防止重复问题的泛滥)

无法使用设备上的沙箱testing用户login

试图做一些在应用程序内购买testing,所以我创build了一个沙盒testingitunesconnect …但是当我试图以我的设备上的用户login,我得到一个错误: Itunes帐户创build不允许 Apple ID目前无法在iTunes商店中使用。 请稍后再试。 如果我input的帐户的密码错误,我得到一个帐户拒绝,所以它不是一个密码错字..这是发生在我创build的每个testing帐户…任何人都有一个线索到底是怎么回事..我找不到任何地方的任何信息。

如何从UIGestureRecognizer获取UITouch位置

我想从UIGestureRecognizer获取UITouch的位置,但我无法弄清楚如何从文档和其他SO问题中查找。 你们能引导我吗? – (void)handleTap:(UITapGestureRecognizer *)tapRecognizer { CCLOG(@"Single tap"); UITouch *locationOfTap = tapRecognizer; //This doesn't work CGPoint touchLocation = [_tileMap convertTouchToNodeSpace:locationOfTap]; //convertTouchToNodeSpace requires UITouch [_cat moveToward:touchLocation]; } 固定代码在这里 – 这也是固定反转Y轴 CGPoint touchLocation = [[CCDirector sharedDirector] convertToGL:[self convertToNodeSpace:[tapRecognizer locationInView:[[CCDirector sharedDirector] openGLView]]]];

无法同时满足约束embedded在故事板中的AVPlayerViewController的警告

我试图通过embedded一个单独的视图控制器完全通过故事板设置一个AVPlayerViewController。 脚步: 在Xcode中创build单一视图应用程序。 将VCembedded到导航控制器中。 在底部添加工具栏(固定到超级视图(前导,尾随,底部布局指南,高度(44))。 在父视图控制器中添加容器视图(固定到超视图(前导,尾随),顶部布局指南,工具栏顶部)。 删除容器视图附带的默认视图控制器。 从对象库拖动AV Player视图控制器对象。 将容器视图中的embedded式Segue连接到AV播放器视图控制器。 没有添加代码。 这是我的故事板的样子: 查看层次: 一切运行良好: 但问题是:只要我运行它,我得到这些警告在debugging器中: 2015-09-30 12:58:35.904 AVPlayerTest[9352:446772] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; […]