- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让 View Controller 在单击按钮时更改 View ,但我一直收到错误提示:
Thread 1: signal SIGABRT
我想以编程方式完成所有事情,而不是使用 Xcode 中的 Storyboard。我将在下面提供我的代码。 顺便说一句,我正在使用 Swift。
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
let navController = UINavigationController()
let mainViewController = ViewController(nibName:nil, bundle:nil)
// NavigationBar/Title colour
navController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
UINavigationBar.appearance().barTintColor = UIColor(red:3/255, green:60/255, blue:115/255, alpha:1);
// Push the viewcontroller onto the navigation controller
navController.pushViewController(mainViewController, animated:false)
self.window!.rootViewController = navController
self.window?.makeKeyAndVisible()
return true
}
func applicationWillResignActive(application: UIApplication)
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication)
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication)
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication)
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication)
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
self.title = "Title"
self.view.backgroundColor = UIColor.whiteColor()
// button
let btn_Test = UIButton()
btn_Test.backgroundColor = UIColor.redColor()
btn_Test.setTitle("Test Button", forState: UIControlState.Normal)
btn_Test.frame = CGRectMake(0, 100, 100, 100)
btn_Test.addTarget(self, action:"onTestButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn_Test)
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//=========================================================================
// Button Click Events
//=========================================================================
func onTestButtonClicked(sender: UIButton)
{
let webviewController = WebviewController()
self.navigationController?.pushViewController(webviewController, animated:true)
}
}
希望有人能帮忙。我已经坚持了几个小时了,我知道这可能很容易解决。
已编辑
AppDelegate.swift 中出现错误:AppDelegate 类:UIResponder、UIApplicationDelegate
控制台输出:
2016-02-25 14:07:56.526 MyApp_NativeSwift[1027:6035] -[MyApp_NativeSwift.ViewController onTestButtonClicked]: unrecognized selector sent to instance 0x7fb7c1f13530
2016-02-25 14:07:56.530 MyApp_NativeSwift[1027:6035] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyApp_NativeSwift.ViewController onTestButtonClicked]: unrecognized selector sent to instance 0x7fb7c1f13530'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f38de65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001112f5deb objc_exception_throw + 48
2 CoreFoundation 0x000000010f39648d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f2e390a ___forwarding___ + 970
4 CoreFoundation 0x000000010f2e34b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010fdd4194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010ff436fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010ff439c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x000000010ff42af8 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010fe4349b -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010fe441d0 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010fdf2b66 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010fdccd97 _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010f2b9a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010f2af95c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010f2aee13 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010f2ae828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x00000001148eaad2 GSEventRunModal + 161
18 UIKit 0x000000010fdd2610 UIApplicationMain + 171
19 MyApp_NativeSwift 0x000000010f1abe3d main + 109
20 libdyld.dylib 0x0000000111dfe92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
最佳答案
您需要更改此行:
btn_Test.addTarget(self, action:"onTestButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
对此:
btn_Test.addTarget(self, action:"onTestButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
您已将目标的操作指定为不带参数的函数名称 onTestButtonClicked,额外的“:”表示它有一个参数。
关于ios - swift -线程 1 : Signal SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35628892/
来自Unix&Linux Stack Exchange的 This question was migrated,因为可以在Stack Overflow上进行回答。
所以我有这段代码(部分取自 python 文档): import signal def handler(signum, frame): print 'Signal handler called
是否可以在信号块中调用用户定义的方法? method my-method ( ... ) { signal(SIGTERM,SIGINT,SIGQUIT,SIGHUP).tap( -> $si
我正在研究一个类的概念性伪代码信号量分配。 我想知道是否可以在某个进程调用 wait() 之前在信号量上调用 signal()。例如: Shared data: Semaphore x = 0; Pr
我正在为远程调试注册一个信号: signal.signal(signal.SIGUSR1, lambda x,y: remote_debug(x, y, emp_id)) 虽然通常非常快,但日志语句显
关于 PySide signals and slots page它说:“信号是实例拥有的运行时对象,它们不是类属性”。显然,QObject 构造函数在 Signals 的类属性中查找并将它们复制到对象
关于 PySide signals and slots page它说:“信号是实例拥有的运行时对象,它们不是类属性”。显然, QObject 构造函数查找 Signals 的类属性并将它们复制到对象实
关于PySide signals and slots page它说:“信号是实例拥有的运行时对象,它们不是类属性”。显然,QObject 构造函数在类属性中查找信号并将它们复制到对象实例。我的测试程序
使用 ReactiveCocoa,我如何从重复信号中链接信号? 我想做这样的事情:每 5 秒,我运行一次网络请求。 为此,我创建了一个重复信号 RACSignal *each5SecondSignal
正如标题中所写 - “信号和插槽”是一种简单的响应式(Reactive)编程方式吗? 最佳答案 Signals/Slots是 Observer Pattern 的实现. 来自维基 Reactive P
您好,我想知道信号声明如何在 VHDL 中真正起作用。它是否意味着延迟,因为它是内部信号?信号有内部存储器吗? 例子: Architecture SD_BEH of SD is signal C: s
我正在尝试编写一些代码来使用 python 执行一些数据包嗅探 使用 pyshark.I 有以下一段代码: import pyshark print('Pyshark demo') capture =
**披露 - 我是一名初学者 C 程序员,并不完全熟悉如何解释手册页,也不完全熟悉谈论 C 时正确的单词选择 - 对这个问题的任何编辑或澄清都是感谢。* 问题:我正在阅读有关 signal(7) 的手
我的应用程序运行完美,没有任何问题。但是当我尝试调试它时,android studio 卡住了。所以我收到消息“等待调试器”,然后该消息消失,接下来我在模拟器中只看到黑屏。 我也收到了消息 SIGNA
我在 Laravel 5.7 中使用 Snappy PDF 库。在本地一切正常,但在我的开发环境中出现此错误:该进程已收到信号“11”的信号。到现在为止,我找不到可以帮助我的解决方案。这是我在 Con
当我想在 linux 上激活 mongo 时,我得到了这个错误,它不会工作 $ sudo systemctl status mongod ● mongod.service - MongoDB 数据库服
我正在尝试设置函数超时,但我无法成功。 我运行来自 https://docs.python.org/3/library/signal.html?highlight=signal%20sigalrm#e
我在尝试使用 Phantomjs 和 Symfony 的 Process 和 Reposonse 文件创建 PDF 文档时遇到此错误。 这是我收到的错误信息 fatal error :未捕获的异常 '
我正在尝试调试一个复杂的 Perl 应用程序,该应用程序以错误消息“收到信号 SIGCHLD,但未设置信号处理程序”而终止。我知道它来自 Perl 解释器本身,特别是来自文件 mg.c它不能被捕获。但
我有以下代码,它按预期工作: import signal def printer(signum, frame): print("hi!") signal.signal(signal.SIGAL
我是一名优秀的程序员,十分优秀!