目标C语言 线程1信号SIGBART错误放在按钮或标签iOS



我不明白为什么我不能在我的文件中放置任何标签或按钮。每次我这样做,它就崩溃了,并出现线程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) 

我想我把它修好了。我试图同时使用标签和按钮。我删除了标签,现在它工作得很好

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

您需要删除到不存在的出口的连接(并将其连接到存在的东西)

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

可以使用-(void)didMoveToSuperview方法来定制UI,而不是drawRect。然而,除了特殊情况,最好自定义UIView子视图,当它从父视图控制器初始化,你有所有你需要的,更重要的是,它是一个同步调用。

最新更新