索引0超越了空数组的界限,同时进入文档目录
我使用下面的代码来到文档目录。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0];
为什么我的应用程序会崩溃以下消息?
*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
我看不到我的NSArray
(不可变数组)如何是空的。 该函数应该返回数组中的文档文件夹。 有任何想法吗?
1)你确定崩溃吗?
2)不完全相关,但可以帮助 。
由NSSearchPathForDirectoriesInDomains
返回的NSSearchPathForDirectoriesInDomains
中有零个元素。 它是空的。 究竟是什么错误消息说。
不回答为什么 ,但自Xcode 5:
NSString *documentsDirectory = [paths firstObject];
如果它是空的,它不会引发exception,它将返回零。 没有崩溃。
尝试使用NSHomeDirectory()
而不是…这是一个更好的方式来获取应用程序的主目录。
注意:如果您位于文档目录之后,那么您可能需要将@"Documents/"
附加到该string
- 在一段时间后显示UIAlertView
- 和UIGestureRecognizer一起听UITouch事件
- 绘制UIImage时无效的上下文错误
- UIViewanimation在视图顶部与轴交替
- 在iBooks中打开pdf的UIDocumentInteractionController崩溃
- 如何在iOS中实现画笔描边
- UISearchController:searchBar和scopeBar在第一个触摸事件上重叠
- iOS – 多个NSURLConnection下载
- iOS:在当前的模式视图控制器后面切换视图控制器?
外部附件框架蓝牙对。 每次连接配件数0
我想用蓝牙尝试读/写数据
我试试双:
Mac Book < – > iPod 4
自定义设备< – > iPod 4
我试试这个苹果示例(EADemo) https://developer.apple.com/library/ios/samplecode/EADemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010079
我在设置 – >蓝牙中创build了一对:
Mac Book < – > iPod 4 – ok(已连接)
自定义设备< – > iPod 4 – 确定(已连接)
但
[[EAAccessoryManager sharedAccessoryManager] connectedAccessories]
总是获得数组0。
有任何想法吗?
谢谢。
EADemo使用外部附件框架,因此需要在项目的info.plist中添加一个协议string。 这是苹果用来locking非MFi配件的连接。 有关更多信息,请查看MFi程序
- iOS在另一个项目中使用现有项目的类/资源文件
- 呈现模态视图控制器隐藏导航栏
- 在iOS上创build一个很好的自定义表情聊天体验
- 循环缓冲录音iOS:可能吗?
- 在iPhone上检测长按
- 如何在iOS中使用popup式菜单?
- '无法识别的select器发送到实例'
- App Store的代码与iPhone 3G上的Xcode / Device代码不同
- 如何使.xib文件兼容iOS7,iOS6和更早版本
导出应用程序用于企业分发时的0授权
当试图为Enterprise Distribution导出一些iOS应用程序时,我遇到了一个问题,即组织者为我的应用程序显示“0权利”,而未selectconfigurationconfiguration文件。
这在创build.IPA文件时不会导致任何错误。 但是,在我的网站上放置.ipa和.plist后,应用程序将无法成功安装。 当我尝试安装时,它会在“正在加载…”时开始在应用程序图标上显示进度指示器,但随后消失,我得到一般消息:
无法下载应用程序 – 目前无法安装“ 我的应用程序名称 ”。
并带有重试选项。
我没有与我的其他几个应用程序,这显示了4个权利和configuration文件在组织者的这个问题。 生产供应configuration文件是一个“公司通配符”,所以它具有结构com.mycompanyname.*
我已经确认工作和非工作代码的App ID遵循完全相同的结构。 在我select用于configuration的开发团队之后,工作应用程序似乎会自动选取configuration文件,在这里可以看到其中一个工作应用程序:
即使我在目标的“生成设置”中专门select了我的生产分销configurationconfiguration文件,但在尝试分发我的应用时,configurationconfiguration文件不包括在内。
试图解决这个问题,我已经尝试了答案中列出的所有步骤,以及一些未被接受的答案中的几个解决方法: iOS 8 – 无法安装企业应用程序 。 供参考而不必点击通过;
- 修复1:我没有在清单中包含图像,所以我知道他们没有错。
- 修复2:问题的应用程序只有几个月的时间,我testing的iOS 8的设备,因为它出来的一天。
- 修复3:我已经确认我的configuration文件处于活动状态
- 修复4:我没有在控制台中得到
Verification Stage Failed
错误 - 其他:尝试从步骤@托马斯的答案手动创build我的.ipa
- 其他:我没有在控制台中得到重复的bundleID错误
- 其他:我已经尝试在我的目标的常规选项卡上设置我的“团队”为我的实际开发帐户,并“无”
我在智慧的结尾试图弄清楚为什么我的权利没有出现在组织者的第一位,所以任何build议都非常受欢迎。 下面我把我认为是我的设备的控制台相关的日志,当它无法安装我的应用程序(有点编辑):
Jan 19 10:37:47 My-Device-Name SpringBoard[48] <Warning>: Killing com.companyName.AppName for app installation Jan 19 10:37:47 My-Device-Name itunesstored[82] <Warning>: LaunchServices: installing app for existing placeholder <LSApplicationProxy: 0x12ed94f40> com.companyName.AppName (Placeholder) Jan 19 10:37:47 My-Device-Name itunesstored[82] <Warning>: LaunchServices: Creating installProgressForApplication:<LSApplicationProxy: 0x12ed94f40> com.companyName.AppName (Placeholder) withPhase:1 Jan 19 10:37:47 My-Device-Name lsd[74] <Warning>: LaunchServices: Updating installPhase for parent <NSProgress: 0x1345516b0> : Parent: 0x0 / Fraction completed: 0.5100 / Completed: 51 of 100 to 1 Jan 19 10:37:47 My-Device-Name installd[40] <Notice>: 0x100484000 -[MIClientConnection _doBackgroundInstallationForPath:withOptions:completion:]: Install of "/var/mobile/Media/Downloads/4200584489248642015/-6824318255463645847" type Customer requested by itunesstored (pid 82) Jan 19 10:37:47 My-Device-Name installd[40] <Error>: 0x100484000 +[MIInstallable installablesAtURL:packageFormat:userOptions:error:]: 52: Failed to inspect package at file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted (Error Domain=NSPOSIXErrorDomain Code=2 "_IterateDirectory for file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted/Payload returned No such file or directory" UserInfo=0x15d61c6b0 {SourceFileLine=413, NSLocalizedDescription=_IterateDirectory for file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted/Payload returned No such file or directory, FunctionName=-[MIFileManager urlsForItemsInDirectoryAtURL:error:]}) Jan 19 10:37:47 My-Device-Name itunesstored[82] <Error>: 0x10231c000 __MobileInstallationInstallForLaunchServices_block_invoke240: Returned error Error Domain=MIInstallerErrorDomain Code=6 "Failed to inspect package at file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted" UserInfo=0x12ee51240 {NSLocalizedDescription=Failed to inspect package at file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted, LegacyErrorString=PackageInspectionFailed, FunctionName=+[MIInstallable installablesAtURL:packageFormat:userOptions:error:], SourceFileLine=52, NSUnderlyingError=0x12ef3e6f0 "_IterateDirectory for file:///private/var/mobile/Library/Caches/com.apple.mobile.installd.staging/temp.7eIGCb/extracted/Payload returned No such file or directory"} Jan 19 10:37:47 My-Device-Name itunesstored[82] <Warning>: ERROR: MobileInstallationInstallForLaunchServices returned nil Jan 19 10:37:47 My-Device-Name lsd[74] <Warning>: LaunchServices: installation failed for app com.companyName.AppName Jan 19 10:37:47 My-Device-Name itunesstored[82] <Warning>: LaunchServices: installPhaseFinishedForProgress: com.companyName.AppName.Installing - <NSProgress: 0x13004e800> : Parent: 0x0 / Fraction completed: 0.0000 / Completed: 0 of 100 called, removing progress from cache
就像不久前的SSL改变一样,在Xcode 6中,我可以通过重新阅读文档来确认,然后调用苹果支持来validation。 您不能再使用通配符App ID分配企业应用程序。 在供应configuration文件中寻找一个告诉故事XC:com.company。*。
根据苹果的情况,当技术人员拿着一个最小的testing应用程序,以及我自己最小的testing用例时,您可以创build新的显式应用程序ID并编辑现有的供应configuration文件以使用它们。 因此对现有的安装影响最小。 这是没有证实的天气之一,可以恢复到Xcode 5后,在xCode 6中使用该捆绑ID后存档。我希望这个信息可以帮助其他企业的开发人员。 https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/DistributingEnterpriseProgramApps/DistributingEnterpriseProgramApps.html 。
我发现问题的解决scheme,那就是为所有的应用程序创build明确的应用程序ID。 我不知道在生产应用程序中使用通配符应用程序ID是否存在新问题,但是当我创build显式ID(以及每个显式ID的configuration文件)时,我不再遇到问题。
仍然不知道为什么通配符configuration文件是由我的一些应用程序,但不是由其他人拿起,但至less有一个解决scheme是可用的。
- 如何保留核心数据中的有序列表
- 如何将构build发送到已configuration的远程人员的iPhone
- 核心数据:发送KVO通知,以获取瞬态派生属性
- 用animation交换rootViewController
- 在初始化时将parameter passing给自定义类
- iOS – 从作为parameter passing的块中获取variables
- 从NSNumber获取CGFloat的最常见和最正确的做法是什么?
- 如何检测UITextField的点击?
- 当我在iPad上运行iPhone应用程序时,屏幕分辨率是错误的。 如何解决这个问题?
应用内购买错误代码0
我正在尝试排查错误代码为0的“无法连接到iTunes Store”的原因。
我知道我的应用程序标识符是好的,因为我检索应用程序启动时的产品信息并logging结果,并从iTunes获得正确的产品标识符和价格。 当我改变我的应用程序标识符到一些愚蠢的,这失败了。
我知道我的产品标识符也很好,因为上述原因(否则不起作用,我再次检查)。
我试图用两种不同的方式创build一个SKPayment:
第一种方式
SKPayment *payment = [SKPayment paymentWithProductIdentifier:productIdentifier]; // This is deprecated in ios 5 but should work [[SKPaymentQueue defaultQueue] addPayment:payment];
第二种方法
SKPayment *payment = [SKPayment paymentWithProduct:foundProduct]; [[SKPaymentQueue defaultQueue] addPayment:payment];
(foundProduct来自从SKProductsRequest返回的SKProducts的数组)
这两种方式失败,错误代码为0。
我已经在运行iOS 5.0.1的iPhone 4S和iOS 5的模拟器上尝试了这一点。
我读过硬复位工作( 2359739 )这似乎是疯了,但我继续尝试在模拟器(iOS模拟器=>重置内容和设置…)无济于事。
唯一我能想到的是,也许iTunes沙盒服务器是不可靠的…
尝试使用不正确的iTunes Connecttesting帐户也可能导致此错误。 如果您尝试为另一个团队使用testing帐户而不是您正在testing的应用程序注册到的那个团队,那么它将导致相同的错误,而没有更具体的消息。
感谢@ user1120741和@让我们来validation这是一个苹果的问题,并发布补丁时。
因为苹果公司并没有为我们提供一个简单的方法来查看这样的系统问题,所以开发人员只能猜测全function的代码。
道德:检查Twitter,SO和其他网站,当你有这样的问题。 如果你确定你有代码运行,你已经模拟了模拟器,但它仍然不起作用,告诉别人你的问题(Twitter,SO等),只需等待几个小时。
这种错误(未知错误或错误= 0)是由两个主要类别的各种原因造成的。 一个是testing用户帐户的问题(不一样的国家,不活跃,不知何故被苹果等封锁)另一个是
payment.productIdentifier
当你由于错字或其他原因而给出错误的时候。
- iOS 8启动图像文件 – 导航栏和状态栏
- UIView中的黑色背景?
- 什么时候应该使用IBOutlets的弱或强限定符?
- 当YouTubevideo结束或完成button按下时捕捉iOS事件
- UIRefreshControl在应用程序不活动后停止旋转
- @synchronized()做了什么?
- popup详细视图后自动取消select表视图单元格?
- 访问使用iTunes传输的“私人文档”文件夹中的文件
- 在NSDateFormatter中,不能在一年之前放置单引号
查看收到的通知后,将徽章值重置为0
过去几天,我一直试图在收到notification
时增加badge
值。 每当收到通知时,我都会设置一个观察者来增加指定的徽章值。 它工作得很好:
//adds the observer. if it goes off then add one to the notification badge NotificationCenter.default.addObserver(forName: PRIVATE_NOTIFICATION, object: nil, queue: nil) { (notification) in //increment a variable self.privateBadge += 1 if let notificationTab = self.tabBar.items?[1]{ if self.tabBar.selectedItem != notificationTab as UITabBarItem { notificationTab.badgeValue = "\(self.privateBadge)" if #available(iOS 10.0, *) { notificationTab.badgeColor = ChatMessageCell.indexedColor } else { // Fallback on earlier versions } }} }
我的问题是试图让variables(privateBadge)重置一旦观察员被删除。 在viewDidAppear
中获取通知标签的标签,我有一个方法设置为在用户点击该标签后将标记值重置为0:
//View Will Appear override func viewWillAppear(_ animated: Bool) { //Removes the badgeValue and resets messageBadge to 0 in an attempt to start the loop over. if let thisTab = self.tabBarController?.tabBar.items?[1]{ NotificationCenter.default.removeObserver(self, name: PRIVATE_NOTIFICATION, object: nil) thisTab.badgeValue = nil tabBarControllerClass.privateBadge = 0 } }
badgeValue清除它应该但我的问题是当我收到另一个通知会发生什么。 而不是从0开始,然后递增到1,它会从剩下的地方开始。 因此,举例来说,如果我收到2个通知,badgeValue将等于2.如果我使用badgeValue进入该选项卡,它将清除并重置为0,但不会。 相反,下一次我收到通知时,它会说3而不是1。
有没有更好的解决scheme? 我应该build立一个协议/代表系统吗?
这看起来像你的坏男孩,
self.privateBadge += 1
你可能忘了把它设回0,
thisTab.badgeValue = nil self.privateBadge = 0
不知道这是否可能在你的情况下,因为我不知道这是否是同一class。
- WKWebView捕获HTTP错误代码
- 如何获得有很多图像(50-200)snappy UICollectionView?
- UITextField键盘在加载时阻塞runloop?
- UIViewAnimationOptionBeginFromCurrentState具有基本animation的意外行为
- 从文本字段插入数据到SQLite数据库
- UISplitViewController主/从通信
- ARC和非ARC NSString初始化
- 我怎样才能以编程方式closures键盘?
- 滚动到底部时将行添加到UITableView
核心数据示例,无效更新:部分0中的行数无效
我是iOS和XCode的新手,正在通过一个核心数据教程,我真的难住。 我不断地在下面的错误日志中得到错误:
Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Crashed Thread: 0 Dispatch queue: com.apple.main-thread Application Specific Information: iPhone Simulator 235, iPhone OS 4.2 (iPad/8C134) *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).' *** Call stack at first throw: ( 0 CoreFoundation 0x010a6be9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x00e9b5c2 objc_exception_throw + 47 2 CoreFoundation 0x0105f628 +[NSException raise:format:arguments:] + 136 3 Foundation 0x000b447b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 UIKit 0x00336a0f -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8424 5 UIKit 0x00325f81 -[UITableView insertRowsAtIndexPaths:withRowAnimation:] + 56 6 SimpleRes 0x00002496 -[RootViewController addReservation] + 465 7 UIKit 0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119 8 UIKit 0x004c7167 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156 9 UIKit 0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119 10 UIKit 0x003481b5 -[UIControl sendAction:to:forEvent:] + 67 11 UIKit 0x0034a647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 12 UIKit 0x003491f4 -[UIControl touchesEnded:withEvent:] + 458 13 UIKit 0x002de0d1 -[UIWindow _sendTouchesForEvent:] + 567 14 UIKit 0x002bf37a -[UIApplication sendEvent:] + 447 15 UIKit 0x002c4732 _UIApplicationHandleEvent + 7576 16 GraphicsServices 0x018bda36 PurpleEventCallback + 1550 17 CoreFoundation 0x01088064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 18 CoreFoundation 0x00fe86f7 __CFRunLoopDoSource1 + 215 19 CoreFoundation 0x00fe5983 __CFRunLoopRun + 979 20 CoreFoundation 0x00fe5240 CFRunLoopRunSpecific + 208 21 CoreFoundation 0x00fe5161 CFRunLoopRunInMode + 97 22 GraphicsServices 0x018bc268 GSEventRunModal + 217 23 GraphicsServices 0x018bc32d GSEventRun + 115 24 UIKit 0x002c842e UIApplicationMain + 1160 25 SimpleRes 0x00001ab0 main + 102 26 SimpleRes 0x00001a41 start + 53 )
这是我的addReservation代码:
-(void)addReservation{ // Create and configure a new instance of the Event entity. Reservations *reservation = (Reservations *)[NSEntityDescription insertNewObjectForEntityForName:@"Reservations" inManagedObjectContext:managedObjectContext]; [reservation setEnd_Time: [[NSDate alloc]init]]; [reservation setReservation_Date:[[NSDate alloc]init]]; [reservation setStart_Time:[NSDate date]]; [reservation setParty_Size: [NSNumber numberWithInt:4]]; [reservation setPhone_Number: [NSNumber numberWithInt: 1234567890]]; [reservation setName: @"Keith"]; [reservation setNotes: @"He's really hot!"]; [reservation setPerson_Responsible: @"Lisa"]; [reservation setTables_Excluded: @"3,5,8"]; NSError *error = nil; if (![managedObjectContext save:&error]) { } [resArray insertObject:reservation atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]; }
我相信我的resArray没有从我以编程方式input的方法获取数据,但我不确定,我不知道如何解决它。
任何帮助表示赞赏。
我会看看你的执行情况
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
如果从numberOfRowsInSection返回的值不等于之前的值加上使用insertRowsAtIndexPaths添加的行数,则会发生指定的错误。 如果您的numberOfRowsInSection实现正在使用[myArray count],那么请确保使用的数组实例与添加预留条目的实例相同。 如果你还没有实现这个方法,那将是你的问题。 这是一个如何看待这个方法的例子:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [resArray count]; }
作为备份,您可以添加日志语句,在添加之前和之后以及numberOfRowsInSection函数的内部添加列出数组大小的日志语句。
您从tableView中删除/插入的顺序以及从基础数据源中删除/插入的顺序可能很重要。 Apple文档首先更新视图,然后更新数据源。 但是,从内部视图删除/插入调用- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
,如果你像我一样,返回基础数据源的count
。 因为这没有改变,运行时将会抱怨并崩溃。 所以先从数据源中删除,然后再删除视图。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [recentImages count]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { // Delete from underlying data source first! recentImages = [recentImages removeObjectAtIndex:indexPath.row]; // Then perform the action on the tableView if (editingStyle == UITableViewCellEditingStyleDelete) { [tableView beginUpdates]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView endUpdates]; } // Finally, reload data in view [self.tableView reloadData]; }
对我来说,看起来好像在插入对象之前,先对其进行相应的更改。 我可能是错的,因为我也是一个新手!
-
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}
-
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if(editingStyle == UITableViewCellEditingStyleDelete){
[self.tableView beginUpdates]; // Delete the object that was swiped YourTableName *objectToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath]; NSLog(@"Deleting (%@)", objectToDelete.fieldname); [self.managedObjectContext deleteObject: objectToDelete]; [self.managedObjectContext save:nil]; // Delete the (now empty) row on the table [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView reloadData]; [self.tableView endUpdates]; }
}
这在使用fetchedResultsController删除logging并将其添加到核心数据表时有效。
- iOS 8的自我大小单元不适用于UITableViewCellStyleSubtitle和numberOfLines = 0?
- ios UTF8编码从nsstring
- 使用淡出animation重绘UIView?
- UIScrollView没有响应委托
- UISearchDisplayController – 如何预载searchResultTableView
- 停止一个声音在播放另一个之前
- 切换到iOS 5后无法播放系统声音
- 当它调用“presentViewController:”时,UIAlertController被移动到屏幕顶部的马车位置
- UITextField rightViewMode奇怪的行为
整数除法后浮点数为0
这可能是一个简单的解决scheme,但我无法修复它。
我分2个整数:
finishedGameFinalScore = [score integerValue]; CGFloat interval = 2/finishedGameFinalScore; NSLog(@"interval = %f",interval);
该日志返回0.000000
小数位数是否有限制? 我需要保留十进制结果。
谢谢Shani
你的代码不起作用的原因是你将整数除以另一个整数,然后将结果转换为浮点数。
所以你有2(一个整数)和一些其他的数字(也是一个整数)。 然后你用这个数字除以2,这可能大于2.假设它是3。
Integer
见2/3,他就像“0.66666667?Pshh,反正没有人需要小数点后面的东西”。 所以他截断了它。 你只有0。
然后Integer
把这个数字给了先生, float
先生很高兴得到一个数字! 他就像“耶,一个0!我要添加所有重要的数字”。 这就是0.0000000。
所以是的,首先投到一个浮动。 甚至是双倍!
@ 达斯汀说,你将需要将你的分频器值作为浮点数来浮动 ,它显示整数值
案例1:types转换
NSString *score = @"3"; int interval = [str intValue]; CGFloat interval = (2/(float)interval); NSLog(@"interval = %.2f",interval);
情况2:不需要types转换
NSString *score = @"3"; float interval = [str floatValue]; CGFloat interval = (2/interval); NSLog(@"interval = %.2f",interval);
只要在数字2中加上f-hint就可以了。
CGFloat interval = 2.0f/finishedGameFinalScore;
所有上面/下面的答案是正确的,充分解释为什么这项工作。
只是从1.0中分配长的值,并赋值给浮点型variables。
unsigned long l1 = 65536; unsigned long l2 = 256; float f = (l1/1.0)/(l2/1.0); NSLog(@"%f",f);