在 Xcode 5.0.2 中,我创建了一个带有导航 Controller 的简单 iPhone 应用程序(源代码可用 at GitHub),它首先显示带有 Facebook oAuth dialog 的 Web View 并且 - 一旦用户通过身份验证并获取了她的详细信息 - 尝试推送 DetailViewController:
在上面的 Storyboard中,我调用了 segue segue 并将其推送到 ViewController.m 中通过以下代码:
[self performSegueWithIdentifier: @"segue" sender: self];
NSLog(@"id: %@", dict[@"id"]);
NSLog(@"first_name: %@", dict[@"first_name"]);
NSLog(@"last_name: %@", dict[@"last_name"]);
NSLog(@"gender: %@", dict[@"gender"]);
NSLog(@"city: %@", dict[@"location"][@"name"]);
Facebook 用户数据被很好地获取并几乎立即打印出来:
id: 597287941
first_name: Alexander
last_name: Farber
gender: male
city: Bochum, Germany
但是在 segue 发生之前大约一分钟过去了,有时应用程序甚至崩溃了:
2014-01-09 22:11:29.017 oauthFacebook[4012:1403] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DetailViewController 0x8a89cd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key id.'
*** First throw call stack:
(
0 CoreFoundation 0x0173b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014be8b6 objc_exception_throw + 44
2 CoreFoundation 0x017cb6a1 -[NSException raise] + 17
3 Foundation 0x0117f9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x010ebcfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x010eb253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x0114d70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x004cea15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x014d07d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x01736b6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x004cd56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x0033f605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x0033fdad -[UIViewController loadView] + 302
13 UIKit 0x003400ae -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x003405b4 -[UIViewController view] + 35
15 UIKit 0x0035a3e2 -[UINavigationController _startCustomTransition:] + 778
16 UIKit 0x003670c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
17 UIKit 0x00367cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x004a1181 -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x00297267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
20 libobjc.A.dylib 0x014d081f -[NSObject performSelector:withObject:] + 70
21 QuartzCore 0x03b492ea -[CALayer layoutSublayers] + 148
22 QuartzCore 0x03b3d0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x03b3cf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
24 QuartzCore 0x03aa4ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
25 QuartzCore 0x03aa5e71 _ZN2CA11Transaction6commitEv + 393
26 QuartzCore 0x03aa60c2 _ZN2CA11Transaction14release_threadEPv + 226
27 libsystem_pthread.dylib 0x01e7681c _pthread_tsd_cleanup + 93
28 libsystem_pthread.dylib 0x01e7327e _pthread_exit + 108
29 libsystem_pthread.dylib 0x01e73dd8 pthread_workqueue_setdispatchoffset_np + 0
30 libsystem_pthread.dylib 0x01e77cce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
请问这种行为的原因是什么?
更新:
我已经按照 Savana 的建议清理了 IBOutlets(谢谢),但应用程序仍然崩溃:
2014-01-10 10:26:59.379 oauthFacebook[4342:4113] bool _WebTryThreadLock(bool), 0x8be2960: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 0x51481ae WebThreadLock
2 0x452a57 -[UIWebDocumentView _responderForBecomeFirstResponder]
3 0x27da9e -[UIView setUserInteractionEnabled:]
4 0x934d72 -[_UIViewControllerTransitionContext _disableInteractionForViews:]
5 0x368573 -[UINavigationController pushViewController:transition:forceImmediate:]
6 0x3680b5 -[UINavigationController pushViewController:animated:]
7 0x770c65 -[UIStoryboardPushSegue perform]
8 0x76107e -[UIStoryboardSegueTemplate _perform:]
9 0x342280 -[UIViewController performSegueWithIdentifier:sender:]
10 0x29f0 __32-[ViewController fetchFacebook:]_block_invoke
11 0x11da695 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2
12 0x113a945 -[NSBlockOperation main]
13 0x1193829 -[__NSOperationInternal _start:]
14 0x1110558 -[NSOperation start]
15 0x1195af4 __NSOQSchedule_f
16 0x1ae74b0 _dispatch_client_callout
17 0x1ad4018 _dispatch_async_redirect_invoke
18 0x1ae74b0 _dispatch_client_callout
19 0x1ad5eeb _dispatch_root_queue_drain
20 0x1ad6137 _dispatch_worker_thread2
21 0x1e73dab _pthread_wqthread
22 0x1e77cce start_wqthread
(lldb)
而且当我在 performSegueWithIdentifier 调用之前添加 assert([NSThread isMainThread]); 时,我可以看到这不是主线程...
是否需要在主线程上调用 performSegueWithIdentifier?
最佳答案
我已经能够使用以下代码解决我的问题(详细 View Controller 在延迟后显示或应用程序甚至崩溃):
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self performSegueWithIdentifier: @"segue" sender: self];
});
关于ios - performSegueWithIdentifier 需要一分钟以上的时间来执行或崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21031493/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build
我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s