Questions tagged «ios»

iOS是在Apple iPhone,iPod touch和iPad上运行的移动操作系统。使用此标签[ios]来解决与iOS平台上的编程有关的问题。使用相关的标签[objective-c]和[swift]解决那些编程语言所特有的问题。

4
为什么我不能在Swift中的UIViewController上调用默认的super.init()?
我不是UIViewController从情节提要中使用a ,而是要有一个自定义init函数,可以在其中传递NSManagedObjectID某些对象的。我只想像super.init()在Objective-C中一样打电话。像这样: init(objectId: NSManagedObjectID) { super.init() } 但是我收到以下编译器错误: 必须调用超类UIViewController的指定初始化程序 我可以不再这样做吗?

2
如何在Swift中打印'catch all'异常的详细信息?
我正在更新代码以使用Swift,并且我想知道如何为与'catch all'子句匹配的异常打印错误详细信息。我已经对该Swift语言指南页面中的示例进行了稍微修改,以说明我的观点: do { try vend(itemNamed: "Candy Bar") // Enjoy delicious snack } catch VendingMachineError.InvalidSelection { print("Invalid Selection.") } catch VendingMachineError.OutOfStock { print("Out of Stock.") } catch VendingMachineError.InsufficientFunds(let amountRequired) { print("Insufficient funds. Please insert an additional $\(amountRequired).") } catch { // HOW DO I PRINT OUT INFORMATION ABOUT THE ERROR …
84 ios  swift  swift2 

7
以编程方式添加CenterX / CenterY约束
我有一个UITableViewController,如果没有内容可显示,则不显示任何部分。我添加了一个标签,向用户指示此代码无任何显示: label = UILabel(frame: CGRectMake(20, 20, 250, 100)) label.text = "Nothing to show" self.tableView.addSubview(label) 但是现在,我希望它在水平和垂直方向上居中。通常,我会选择屏幕快照中突出显示的两个选项(高和宽另加一个): 我尝试了以下代码来添加约束,但应用程序因错误而崩溃: label = UILabel(frame: CGRectMake(20, 20, 250, 100)) label.text = "Nothing to show" let xConstraint = NSLayoutConstraint(item: label, attribute: .CenterX, relatedBy: .Equal, toItem: self.tableView, attribute: .CenterX, multiplier: 1, constant: 0) let yConstraint = NSLayoutConstraint(item: label, …



7
从不兼容的类型'ViewController * const_strong'分配给'id <Delegate>'
在我的整个应用中,设置时会收到语义问题警告ViewController.delegate = self。我已经搜索并找到了类似的帖子,但没有一个能够解决我的问题。 ViewController.m: GameAddViewController *gameAddViewContoller = [[navigationController viewControllers] objectAtIndex:0]; gameAddViewContoller.delegate=self; 设置时出现错误消息.delegate=self。 GameAddViewController.h: @protocol GameAddViewControllerDelegate &lt;NSObject&gt; - (void)gameAddViewControllerDidCancel:(GameAddViewController *)controller; - (void)gameAddViewController:(GameAddViewController *)controller didAddGame:(Game *) game; @end @interface GameAddViewController : UITableViewController &lt;GameAddViewControllerDelegate&gt; { sqlite3 *pitchcountDB; NSString *dbPath; } @property (nonatomic, strong) id &lt;GameAddViewControllerDelegate&gt; delegate; ... @end ViewController.h: #import "GameAddViewController.h" @class ViewController; …

8
window.onbeforeunload在iPad上不起作用?
有人知道onbeforeunloadiPad是否支持该活动和/或是否有其他使用方式吗? 我已经做了几乎所有的尝试,似乎onbeforeunload从未在iPad(Safari浏览器)上触发该事件。 具体来说,这就是我尝试过的方法: window.onbeforeunload = function(event) { event.returnValue = 'test'; } window.onbeforeunload = function(event) { return 'test'; } (以上两者共同) window.onbeforeunload = function(event) { alert('test')'; } (以上所有功能,但内部 &lt;body onbeforeunload="..."&gt; 所有这些都可以在PC上的FF和Safari上运行,但不能在iPad上运行。 此外,在加载页面后,我还执行了以下操作: alert('onbeforeunload' in window); alert(typeof window.onbeforeunload); alert(window.onbeforeunload); 结果分别是: true object null 因此,浏览器确实具有该属性,但是由于某种原因它没有被解雇。 我尝试离开该页面的方法是单击后退和前进按钮,在顶部栏中进行Google搜索,更改地址栏中的位置,然后单击书签。 有谁知道发生了什么吗?我将不胜感激任何输入。 谢谢

12
带有Alamofire正文的简单字符串的POST请求
在iOS应用中,如何使用Alamofire在HTTP正文中使用简单字符串发送POST请求? 默认情况下,Alamofire需要用于请求的参数: Alamofire.request(.POST, "http://mywebsite.com/post-request", parameters: ["foo": "bar"]) 这些参数包含键值对。但是我不想在HTTP正文中发送带有键值字符串的请求。 我的意思是这样的: Alamofire.request(.POST, "http://mywebsite.com/post-request", body: "myBodyString")
84 ios  http  swift  request  alamofire 

14
获取用于推送通知的设备令牌
我正在处理推送通知。我编写了以下代码来获取设备令牌。 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the view controller's view to the window and display. [self.window addSubview:viewController.view]; [self.window makeKeyAndVisible]; NSLog(@"Registering for push notifications..."); [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; return YES; } - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString …


4
使用自动布局动态更改子视图后调整视图的大小
我不能为上帝的爱而努力,而这正是调整规模的Superview的用处。 我有一个UIView *superview 4 UILabels。2个用作其他2个的标头。 所有4个内容都是动态的,都来自数据库。 SizeToFitvs vs SizeThatFits:(CGSize)vs UIView systemLayoutSizeFittingSize:,通过UILayoutFittingCompressedSize或UILayoutFittingExpandedSize。 我以编程方式使用自动布局,并将Superview高度设置为等于或大于虚拟数字。 在那里,我如何使用这些SizeToFitVS sizeThatFits:(CGSize)VS UIView systemLayoutSizeFittingSize:,无论是传球UILayoutFittingCompressedSize还是UILayoutFittingExpandedSize。我在这里已经阅读了很多技巧,但最终没有结果。 我是否需要重新计算特定位置的Superview约束。Maby在其控制器类中将高度设置为“ @property”,然后删除并读取它吗?Atm我已尝试将所有内容放到任何地方,然后再放一些。我仍然得到相同大小的最终结果,虚拟高度和文本漂浮在外面。即使在子视图上设置了clipsToBound之后。 我正在挠..帮助

16
错误ITMS-90035-Xcode
我已经开发了一个在iPhone上运行完全正常的phonegap应用程序。现在,我想将应用程序提交到appstore。以下是我提交我的应用程序的步骤: 打开Xcode并将项目存档 单击验证(成功) 单击提交到应用商店(这是我收到以下错误的地方) 直到昨天晚上,我什至没有收到这个错误,今天早上,我将项目存档了,并且得到了这个错误。不知道是什么问题。 这是最后一个阶段,这使我无法提交应用程序,这非常令人沮丧,我试图在stackoverflow论坛上搜索相同的错误代码,但我找不到一条与我的错误代码完全相同的帖子,这很奇怪。 请帮忙 :)

2
这个iOS是什么样的讽刺错误?
我有一些用于排序日历日期的代码,如下所示: #if !(TARGET_IPHONE_SIMULATOR) NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"HH:mm dd MMM yyyy" options:0 locale:[NSLocale currentLocale]]; [fmt setDateFormat:formatString]; #else [fmt setDateFormat:@"HH:mm dd MMM yyyy"]; #endif 如果我在模拟器中运行,一切正常。如果我在设备上运行它,则会收到此讽刺调试消息。 2012-09-19 22:40:13.972 APPNAME [4923:907] * -[__ NSCFCalendar components:fromDate:]:日期不能为零 我的意思是,您认为该操作应以零日期表示什么? 现在已经避免了异常。 这些错误中的一些错误将在此投诉中报告,然后进一步的违规将简单地无提示地执行nil导致的任何随机操作。这是这次发生的回溯(由于编译器优化,某些帧可能会丢失): 您必须嘲笑它​​,但是我不确定我的dateFormatFromTemplate:代码有什么问题。任何帮助,将不胜感激。 运行Xcode V 4.5 btw 更新: 回溯: 0 CoreFoundation 0x39ff0e55 + 84 1 APPNAME 0x00040be1-[MeetingsViewController …

6
UICollectionView动画数据更改
在我的项目中,我使用UICollectionView显示图标网格。 用户可以通过单击分段控件来更改顺序,该分段控件调用具有不同NSSortDescriptor的核心数据的访存。 数据量始终相同,只是结束于不同的部分/行: - (IBAction)sortSegmentedControlChanged:(id)sender { _fetchedResultsController = nil; _fetchedResultsController = [self newFetchResultsControllerForSort]; NSError *error; if (![self.fetchedResultsController performFetch:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } [self.collectionView reloadData]; } 问题在于reloadData不会使更改生效,UICollectionView只会弹出新数据。 我应该跟踪更改前后一个单元格在哪个indexPath中,并使用[self.collectionView moveItemAtIndexPath:toIndexPath:]来执行更改动画,或者是否有更好的方法? 我对继承collectionViews没有太多的兴趣,所以任何帮助都将是很大的... 谢谢,比尔。

8
iOS:以编程方式设置UILabel的字体大小
我正在尝试设置UILabel的字体大小。无论我输入什么值,尽管文本大小似乎都没有变化。这是我正在使用的代码。 [self setTitleLabel:[[UILabel alloc] initWithFrame:CGRectMake(320.0,0.0,428.0,50.0)]]; [[self contentView] addSubview:[self titleLabel]]; UIColor *titlebg = [UIColor clearColor]; [[self titleLabel] setBackgroundColor:titlebg]; [[self titleLabel] setTextColor:[UIColor blackColor]]; [[self titleLabel] setFont:[UIFont fontWithName:@"System" size:36]];
83 ios  uilabel 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.