线程 1 在放置按钮或标签 iOS 时发出信号 SIGABRT 错误

Posted

技术标签:

【中文标题】线程 1 在放置按钮或标签 iOS 时发出信号 SIGABRT 错误【英文标题】:Thread 1 signal SIGBART error on putting button or label iOS 【发布时间】:2014-03-17 10:39:41 【问题描述】:

我不知道为什么我不能在我的文件中放置任何标签或按钮。每次我这样做时,它都会因线程 1 错误而崩溃。

@interface PuzzleView : UIView


@property (nonatomic, assign) int row;
@property (nonatomic, assign) int col;
@property (nonatomic, assign) CGFloat dw;
@property (nonatomic, assign) CGFloat dh;

-(NSMutableArray *) getNeighborsForPoint:(CGPoint) point inArray:(NSMutableArray *)array;
-(void) uncover:(CGPoint) point;



@property (retain, nonatomic) IBOutlet UITextField *unflaggedshow;

- (IBAction)swipe:(UISwipeGestureRecognizer *)recognizer;

@end

实现文件

@implementation PuzzleView

@synthesize unflaggedshow=_unflaggedshow;

- (void)drawRect:(CGRect)rect

 _unflaggedshow.text=[[NSString alloc]initWithFormat:@"%0.0d",unflaggedmine1];


- (void)dealloc 
    [_unflaggedshow release];
    [super dealloc];

@end

drawRect 里面还有很多代码,我只是把主要的东西放在这里了。有人可以告诉我为什么我收到线程 1 信号 SIGBART 错误。

谢谢

这些是错误:

#import <UIKit/UIKit.h>

#import "TabBarAppDelegate.h"

int main(int argc, char *argv[])

    @autoreleasepool 
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([TabBarAppDelegate class]));
    

错误:

2014-03-17 06:44:24.836 TabBar-DoubleTap[4603:70b] application:didFinishLaunchingWithOptions
2014-03-17 06:44:24.839 TabBar-DoubleTap[4603:70b] FirstViewController/viewDidLoad
2014-03-17 06:44:24.841 TabBar-DoubleTap[4603:70b] Application windows are expected to have a root view controller at the end of application launch
2014-03-17 06:44:24.844 TabBar-DoubleTap[4603:70b] -----------total mines: 0 ------------
2014-03-17 06:44:24.844 TabBar-DoubleTap[4603:70b] value of gridvalrow from puzzle 12
2014-03-17 06:44:24.844 TabBar-DoubleTap[4603:70b] value of gridvalcol from puzzle 18
2014-03-17 06:44:24.845 TabBar-DoubleTap[4603:70b] field being set ***********
2014-03-17 06:44:24.845 TabBar-DoubleTap[4603:70b] total fields set 400 ******
2014-03-17 06:44:24.846 TabBar-DoubleTap[4603:70b] mine desnity**********  72
2014-03-17 06:44:24.847 TabBar-DoubleTap[4603:70b] ------------------------------------Unflagged Mines 21827753 
2014-03-17 06:44:24.847 TabBar-DoubleTap[4603:70b] PuzzleView/drawRect()
2014-03-17 06:44:25.911 TabBar-DoubleTap[4603:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PuzzleView 0x8b44840> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key unflagged.'
*** First throw call stack:
(
    0   CoreFoundation                      0x01bb65e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014c98b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01c466a1 -[NSException raise] + 17
    3   Foundation                          0x000ff9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x0006bcfb _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x0006b253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   UIKit                               0x004b9e0b -[UIView(CALayerDelegate) setValue:forKey:] + 168
    7   Foundation                          0x000cd70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    8   UIKit                               0x006f1a15 -[UIRuntimeOutletConnection connect] + 106
    9   libobjc.A.dylib                     0x014db7d2 -[NSObject performSelector:] + 62
    10  CoreFoundation                      0x01bb1b6a -[NSArray makeObjectsPerformSelector:] + 314
    11  UIKit                               0x006f056e -[UINib instantiateWithOwner:options:] + 1417
    12  UIKit                               0x00562605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    13  UIKit                               0x00562dad -[UIViewController loadView] + 302
    14  UIKit                               0x005630ae -[UIViewController loadViewIfRequired] + 78
    15  UIKit                               0x005635b4 -[UIViewController view] + 35
    16  UIKit                               0x0059a3ae -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 407
    17  UIKit                               0x00599bd2 -[UITabBarController transitionFromViewController:toViewController:] + 63
    18  UIKit                               0x00595fbb -[UITabBarController _setSelectedViewController:] + 279
    19  UIKit                               0x00595e9c -[UITabBarController setSelectedViewController:] + 180
    20  UIKit                               0x00599ace -[UITabBarController _tabBarItemClicked:] + 312
    21  libobjc.A.dylib                     0x014db874 -[NSObject performSelector:withObject:withObject:] + 77
    22  UIKit                               0x004510c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    23  UIKit                               0x0045104e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    24  UIKit                               0x006ff659 -[UITabBar _sendAction:withEvent:] + 479
    25  libobjc.A.dylib                     0x014db81f -[NSObject performSelector:withObject:] + 70
    26  UIKit                               0x004510c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    27  UIKit                               0x0045104e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    28  UIKit                               0x005490c1 -[UIControl sendAction:to:forEvent:] + 66
    29  UIKit                               0x00549484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    30  UIKit                               0x005490f6 -[UIControl sendActionsForControlEvents:] + 48
    31  UIKit                               0x00703f80 -[UITabBar(Static) _buttonUp:] + 123
    32  libobjc.A.dylib                     0x014db874 -[NSObject performSelector:withObject:withObject:] + 77
    33  UIKit                               0x004510c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    34  UIKit                               0x0045104e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    35  UIKit                               0x005490c1 -[UIControl sendAction:to:forEvent:] + 66
    36  UIKit                               0x00549484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    37  UIKit                               0x00548733 -[UIControl touchesEnded:withEvent:] + 641
    38  UIKit                               0x0048e51d -[UIWindow _sendTouchesForEvent:] + 852
    39  UIKit                               0x0048f184 -[UIWindow sendEvent:] + 1232
    40  UIKit                               0x00462e86 -[UIApplication sendEvent:] + 242
    41  UIKit                               0x0044d18f _UIApplicationHandleEventQueue + 11421
    42  CoreFoundation                      0x01b3f83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    43  CoreFoundation                      0x01b3f1cb __CFRunLoopDoSources0 + 235
    44  CoreFoundation                      0x01b5c29e __CFRunLoopRun + 910
    45  CoreFoundation                      0x01b5bac3 CFRunLoopRunSpecific + 467
    46  CoreFoundation                      0x01b5b8db CFRunLoopRunInMode + 123
    47  GraphicsServices                    0x02a4c9e2 GSEventRunModal + 192
    48  GraphicsServices                    0x02a4c809 GSEventRun + 104
    49  UIKit                               0x0044fd3b UIApplicationMain + 1225
    50  TabBar-DoubleTap                    0x00002992 main + 130
    51  TabBar-DoubleTap                    0x00002905 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我想我成功了。我试图同时使用标签和按钮。我删除了标签,现在它可以正常工作了。

【问题讨论】:

drawRect 改值的地方不对,只能画图 您可能希望向我们提供完整的堆栈跟踪。 添加了错误。我还需要添加什么吗? 【参考方案1】:

看起来您曾经拥有一个名为unflagged 的插座,但现在已经不存在了。可能你把名字改成了unflaggedshow

您需要删除与不存在的插座的连接(并将其连接到存在的插座)。

【讨论】:

【参考方案2】:

drawRect 被调用时,尚未配置出口。所以你不能使用drawRect来更新UI。

您可以使用-(void)didMoveToSuperview 方法代替drawRect 来自定义UI。但是,除了特殊情况,最好在从父viewController初始化UIView子视图时自定义它,你有你需要的一切,更重要的是它是一个同步调用。

【讨论】:

以上是关于线程 1 在放置按钮或标签 iOS 时发出信号 SIGABRT 错误的主要内容,如果未能解决你的问题,请参考以下文章

线程 1:由于 XIB 中的未知类而发出信号 SIGABRT

线程如何在完成时发出信号?

如何实现 QPushbutton 来发出 pyqt 信号并调用另一个类?

停止 MFC 线程

当我在 iOS 应用程序的后台任务(使用 GCD)中间按下 1 次主页按钮时,由于信号 9 而终止

QSpinBox信号用于箭头按钮