草庐IT

ios - 社交媒体应用程序的按钮不起作用 - Swift

coder 2024-01-29 原文

<分区>

我目前正在制作一个应用程序,我正在使用带有 Xcode 8.2 beta 的 Swft 3。我正在努力做到这一点,以便用户能够从我的 iOS 项目中的 SWRevealViewController 访问社交媒体。当点击社交媒体按钮时,他们应该打开相应的应用程序。但是,当执行代码并打开 iOS 模拟器时,当我滑动打开 SWRevealViewController(菜单)时,应用程序崩溃了。

完整错误信息:

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TheGunnOracleApp.SocialMedia 0x7ffd0d50c0d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010212dd4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000101b8f21e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010212dc99 -[NSException raise] + 9
    3   Foundation                          0x000000010169db3f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
    4   UIKit                               0x0000000102e8e99f -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x0000000103102c6e -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00000001020d2b60 -[NSArray makeObjectsPerformSelector:] + 256
    7   UIKit                               0x00000001031015f2 -[UINib instantiateWithOwner:options:] + 1867
    8   UIKit                               0x0000000102e950d1 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
    9   UIKit                               0x0000000102e959f3 -[UIViewController loadView] + 177
    10  UIKit                               0x000000010311561c -[UITableViewController loadView] + 84
    11  UIKit                               0x0000000102e95d28 -[UIViewController loadViewIfRequired] + 201
    12  UIKit                               0x0000000102e9657c -[UIViewController view] + 27
    13  TheGunnOracleApp                    0x00000001014d50fb -[SWRevealViewController _deployForViewController:inView:] + 235
    14  TheGunnOracleApp                    0x00000001014d4f58 -[SWRevealViewController _deploymentForViewController:inView:appear:disappear:] + 136
    15  TheGunnOracleApp                    0x00000001014d48c1 -[SWRevealViewController _rearViewDeploymentForNewFrontViewPosition:] + 433
    16  TheGunnOracleApp                    0x00000001014d32f2 -[SWRevealViewController _setFrontViewPosition:withDuration:] + 82
    17  TheGunnOracleApp                    0x00000001014d26c6 __65-[SWRevealViewController _dispatchSetFrontViewPosition:animated:]_block_invoke + 70
    18  TheGunnOracleApp                    0x00000001014d1300 -[SWRevealViewController _enqueueBlock:] + 160
    19  TheGunnOracleApp                    0x00000001014d261b -[SWRevealViewController _dispatchSetFrontViewPosition:animated:] + 251
    20  TheGunnOracleApp                    0x00000001014d0154 -[SWRevealViewController setFrontViewPosition:animated:] + 148
    21  TheGunnOracleApp                    0x00000001014cffed -[SWRevealViewController revealToggleAnimated:] + 93
    22  TheGunnOracleApp                    0x00000001014d05df -[SWRevealViewController revealToggle:] + 63
    23  UIKit                               0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
    24  UIKit                               0x0000000103137971 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 149
    25  UIKit                               0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
    26  UIKit                               0x0000000102e7c344 -[UIControl sendAction:to:forEvent:] + 67
    27  UIKit                               0x0000000102e7c65d -[UIControl _sendActionsForEvents:withEvent:] + 444
    28  UIKit                               0x0000000102e7c7e7 -[UIControl _sendActionsForEvents:withEvent:] + 838
    29  UIKit                               0x0000000102e7b559 -[UIControl touchesEnded:withEvent:] + 668
    30  UIKit                               0x0000000102d63d5d -[UIWindow _sendTouchesForEvent:] + 2747
    31  UIKit                               0x0000000102d6544b -[UIWindow sendEvent:] + 4011
    32  UIKit                               0x0000000102d1254b -[UIApplication sendEvent:] + 371
    33  UIKit                               0x00000001034fda0f __dispatchPreprocessedEventFromEventQueue + 3248
    34  UIKit                               0x00000001034f6745 __handleEventQueue + 4879
    35  CoreFoundation                      0x00000001020d28e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    36  CoreFoundation                      0x00000001020b7b0c __CFRunLoopDoSources0 + 556
    37  CoreFoundation                      0x00000001020b6ff6 __CFRunLoopRun + 918
    38  CoreFoundation                      0x00000001020b6a04 CFRunLoopRunSpecific + 420
    39  GraphicsServices                    0x0000000107e37a6f GSEventRunModal + 161
    40  UIKit                               0x0000000102cf4808 UIApplicationMain + 159
    41  TheGunnOracleApp                    0x00000001014f2d0f main + 111
    42  libdyld.dylib                       0x0000000105ddd68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这是社交媒体中每个按钮的代码。

注意:由于 Facebook 一开始无法正常工作,我删除了其余社交媒体的代码:

import Foundation
import UIKit

class SocialMedia: UITableViewController{
    @IBAction func facebookOpen(_ sender: Any) {
        UIApplication.shared.open(NSURL(string: "https://www.facebook.com/gunnoracle")! as URL)
    }
}

这是我的 Main.storyboard UITableViewController 的截图:

有关ios - 社交媒体应用程序的按钮不起作用 - Swift的更多相关文章

  1. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  2. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  3. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  4. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  5. ruby-on-rails - Rails 应用程序之间的通信 - 2

    我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此

  6. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  7. ruby-on-rails - Rails 应用程序中的 Rails : How are you using application_controller. rb 是新手吗? - 2

    刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr

  8. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  9. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  10. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在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返回它复制的字节数,但是当我还没有下

随机推荐