xcode 面临 UIApplicationMain 返回的麻烦
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15001679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facing trouble with the return of UIApplicationMain
提问by Baloom Boom
I have a error help me please
我有错误请帮助我
2013-02-21 18:43:54.471 BPApp[12574:c07]
*** Assertion failure in -[MainViewController saveEntry:], /Users/Apple/Desktop/BPApp/BPApp/MainViewController.m:66
2013-02-21 18:43:54.473 BPApp[12574:c07] ***
2013-02-21 18:43:54.471 BPApp[12574:c07]
*** Assertion failure in -[MainViewController saveEntry:], /Users/Apple/Desktop/BPApp/BPApp/MainViewController.m:66
2013-02-21 18:43:54.473 BPApp[12574:c07] ***
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not update table'
*** First throw call stack:
(0x2091012 0x119ee7e 0x2090e78 0xc34f35 0x313d 0x11b2705 0xe9920 0xe98b8 0x1aa671 0x1aabcf 0x1a9d38 0x11933f 0x119552 0xf73aa 0xe8cf8 0x1fecdf9 0x1fecad0 0x2006bf5 0x2006962 0x2037bb6 0x2036f44 0x2036e1b 0x1feb7e3 0x1feb668 0xe665c 0x263d 0x2565)
libc++abi.dylib: terminate called throwing an exception.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not update table'
*** First throw call stack:
(0x2091012 0x119ee7e 0x2090e78 0xc34f35 0x313d 0x11b2705 0xe9920 0xe98b8 0x1aa671 0x1aabcf 0x1a9d38 0x11933f 0x119552 0xf73aa 0xe8cf8 0x1fecdf9 0x1fecad0 0x2006bf5 0x2006962 0x2037bb6 0x2036f44 0x2036e1b 0x1feb7e3 0x1feb668 0xe665c 0x263d 0x2565)
libc++abi.dylib: terminate called throwing an exception.
(IBAction)saveEntry:(id)sender
{
int systolic = [systolicText.text intValue];
int diastolic = [diastolicText.text intValue];
NSString *comments = commentsText.text;
NSDate *theDate = [NSDate date];
NSString *sql = [NSString stringWithFormat:@"INSERT INTO summary('theDate', 'systolic', 'diastolic', 'comments') VALUES ('%@', '%d', '%d', '%@')", theDate, systolic, diastolic, comments];
char *err;
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) !=SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, @"Could not update table");
}else{
NSLog(@"table updated");
}
systolicText.text =@"";
diastolicText.text =@"";
commentsText.text =@"";
}
is mymainviewcontroller.m
是我的mainviewcontroller.m
回答by user247
As your error saying , go to the function saveEntryin the MainViewControllerand put the break point at the starting line of the saveEntry function , compile the code line by line . Then you can get the error at which line you are getting .
当你的错误说,去功能saveEntry在MainViewController,把破发点在saveEntry函数的开始行,一行编译代码行。然后你可以得到你得到的那一行的错误。
回答by trojanfoe
The issue is your use of NSAssert()
which should only be used to detect and reject silly developer mistakes (that we are constantly making).
问题是您使用NSAssert()
which 应该只用于检测和拒绝愚蠢的开发人员错误(我们一直在犯)。
You should notuse NSAssert()
for failures that can occur at runtime, and any database interaction can fail.
你应该不使用NSAssert()
的,可以在运行时出现故障,任何数据库交互可能会失败。
Instead you should put that code into a method that returns BOOL
and return NO
if the insert fails. You should also log the reason for the failure, which you can get from sqlite3 using the function sqlite3_errmsg()
(reference).
相反,您应该将该代码放入一个方法中,该方法在插入失败时返回BOOL
并返回NO
。您还应该记录失败的原因,您可以使用函数sqlite3_errmsg()
(参考)从 sqlite3 获取。
After that you need to handle the error by doing anything appropriate to your application; perhaps displaying an alert view and then closing the app, or retrying with different values or, well, anything you can think of to resolve the issue with the least discomfort to the user.
之后,您需要通过执行适合您的应用程序的任何操作来处理错误;也许显示一个警报视图然后关闭应用程序,或者使用不同的值重试,或者,任何你能想到的解决问题的方法,而不会给用户带来最少的不适。