如何检查数组是否为空?(为了记录,我查看了类似的问题,但没有找到有这个确切问题的那个).
我有一个NSMutableArray(让我们称之为nsma)我需要检查是否为空.如果我做NSLog(@"nsma: %@",nsma);它的日志nsma: ( ),但如果我做NSLog(@"nsma count:%@",nsma);它的日志nsma: (null).我需要检查它是否为空,但我的if语句由于某种原因不起作用:
if (nsma == nil)
{
NSLog(@"nsma is empty");
}
Run Code Online (Sandbox Code Playgroud)
有谁知道发生了什么?
我在这里先向您的帮助表示感谢.
我有一个应用程序需要知道它何时崩溃(出于调试目的).当应用程序关闭时,它会调用- (void)applicationWillTerminate:(UIApplication *)application代理.
根据我的理解,当应用程序崩溃时,它不应该调用该行,但出于某种原因它会这样做.(我在那里有代码,NSUserDefaults如果应用程序DID没有崩溃,则设置一个值,但如果DID崩溃则不会改变它.)
一些细节:当- (void)applicationDidBecomeActive:(UIApplication *)application调用时,NSUserDefaults我的程序中的一个键设置为YES.当- (void)applicationWillTerminate:(UIApplication *)application被调用时,同样的按键被设置为NO.下次启动时,应用程序将检查相同的密钥是否设置为YES或NO.计划是检查密钥是否为是,如果是,这意味着它没有正确关闭(即崩溃).
我应该用什么来检查它是否崩溃?
我有一个视图有几个选项,里面是一个从服务器获取数据的表视图.
有没有办法让表格视图自动选择加载时的第一个选项,即viewDidLoad?
我正在使用CoreLocation框架来获取我的速度和距离来计算平均速度.
在CoreLocation发出的第一个更新中,它显示速度和行进距离的负值.我怎样才能解决这个问题?
速度是locationController.locationManager.location.speed其中locationController持有我的CoreLocation委托.通过获取旧位置和新位置并计算距离来计算距离.
//Distance
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// make sure the old and new coordinates are different
if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
(oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
{
mDistance = [newLocation distanceFromLocation:oldLocation];
}
}
Run Code Online (Sandbox Code Playgroud) 如何UINavigationController在按下按钮时显示提示?我已经设置了我的文字[[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt is working!"]];
编辑:为了澄清,我有一个按钮调用一个IBAction设置提示如下,但我需要找到一种方法,一旦按下该按钮显示提示:
-(IBAction)test:(id)sender
{
[[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt works!"]];
//I want it to display right after I set it, so I'm missing something and can't figure it out through the documentation
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试[[[self navigationController]navigationBar]pushNavigationItem:nav animated:YES];但是会引发错误说明Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.
我CoreData在我的applcation中使用,它采用坐标并将它们(以及其他数据)保存到持久性存储中.
应用程序流程如下所示:用户按下按钮,每次用户移动时都会添加坐标,并将它们放入managedObjectContext.用户按下另一个按钮,应用程序停止将坐标放入managedObjectContext并询问用户是否要保存其数据.如果用户想要保存他们的数据,我会打电话[managedObjectContext save:&error];并检查错误.如果用户不想保存,坐标就会managedObjectContext直到应用程序完全关闭并重新打开.
如何删除用户不想保存的那些点?
我正在浏览文档,因为我要实现一个协议而不是一个类(我之前从未做过的事情),而且我很好奇两者之间的区别.
有人能举一个简单的例子吗?
谢谢
假设我在API users/1/items返回的列表items为user为1的ID.
假设API响应如下:
{
"items": [
{
"id": "1",
"description": "Some item"
}
]
}
Run Code Online (Sandbox Code Playgroud)
请注意,响应不包含user_idfor关系映射.是否可以在RestKit 0.20中映射到user_idURL中(在本例中为1)?如果是这样,怎么样?我在docs/wiki中找不到任何提及.
所有,
我想跟踪启动之间的几个不同的事情,如设置,整数等.我不确定Core Data是否是我需要的,因为我不需要多次为实体设置一个值,显示在列表视图等.我应该使用什么?
谢谢
所有,
我创建的应用程序第一次完美运行,但是如果我通过屏幕底部的栏强制关闭它并将其打开,它会崩溃并且不会重新加载.我得到的唯一错误是Thread 1: Program received signal: "SIGKILL".日志中没有任何内容.这在iPhone模拟器和我的物理iPhone中都会发生.
编辑:我已附加调试日志.就像我提到的,没有任何表现.这是抛出错误并且应用程序崩溃后的日志.
GNU gdb 6.3.50-20050815 (Apple version gdb-1703) (Thu May 26 17:11:52 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to …Run Code Online (Sandbox Code Playgroud) objective-c ×10
iphone ×7
ios ×4
xcode ×4
class ×1
cocoa-touch ×1
core-data ×1
protocols ×1
restkit ×1
uitableview ×1