iOS Card *card=[self.deck drawRandomCard];引起线程1:信号SIGABRT
Posted
技术标签:
【中文标题】iOS Card *card=[self.deck drawRandomCard];引起线程1:信号SIGABRT【英文标题】:iOS Card *card=[self.deck drawRandomCard]; Causing Thread 1:signal SIGABRT 【发布时间】:2015-01-19 08:46:26 【问题描述】:我正在做斯坦福 ios7 CS193P Lecture2 作业,有一个问题我不明白。有趣的是我第二次翻转卡片时会发生这种情况。 这里是 wraning libc++abi.dylib: terminating with uncaught exception of type NSException
#import "ViewController.h"
#import "PlayingCardDeck.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *fliplabel;
@property(strong,nonatomic)Deck *deck;
@property(nonatomic)int flipscount;
@end
@implementation ViewController
-(void)setFlipscount:(int)flipscount
_flipscount=flipscount;
self.fliplabel.text=[NSString stringWithFormat:@"Flips: %d",self.flipscount];
-(Deck *)deck
if (!_deck)
_deck=[self createDeck];
return _deck;
-(Deck *)createDeck;
return [[PlayingCardDeck alloc] init];
- (IBAction)touchCardButton:(UIButton *)sender
if ([sender.currentTitle length])
[sender setBackgroundImage:[UIImage imageNamed:@"cardback"] forState:UIControlStateNormal];
[sender setTitle:@"" forState:(UIControlStateNormal)];
else
Card *card=[self.deck drawRandomCard];
[sender setBackgroundImage:[UIImage imageNamed:@"cardfront"] forState:UIControlStateNormal];
[sender setTitle:[card contents] forState:(UIControlStateNormal)];
self.flipscount++;
如果我在 (IBAction)touchCardButton:(UIButton *)sender 中删除 Card *card=[self.deck drawRandomCard] 那么它工作正常,这是怎么发生的,我该如何解决它,有人请帮助我 PS:我没有更改我的标签名称
有我的错误页面:
int main(int argc, char * argv[])
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
**Thread1:signal SIGABRT**
这是我的输出:
25 libdyld.dylib 0x000000010a412145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
这是我的drawRandomCards:
-(Card *)drawRandomCard
Card *randomcardCard=nil;
unsigned index = arc4random() % [self.cards count];
randomcardCard = self.cards[index];
[self.cards removeObjectAtIndex:index];
return randomcardCard;
【问题讨论】:
显示整个错误信息。您能否也显示drawRandomCard
中的内容?
@Larme 我把我的错误信息和 drawRandomCard 放在上面。
如果您转到 Xcode 的断点导航器并在所有 Objective-C 异常上添加断点,该错误应该会导致您停在有用的地方而不是 main()
内。这将引导您找到造成麻烦的实际线路。
顺便问一下,当你遇到错误时,drawRandomCard
中的[self.cards count]
的值是多少?
【参考方案1】:
首先,检查“drawRandomCard”中的“index”值。也许 self.cards 数组没有你要进入的索引
randomcardCard = self.cards[index];
【讨论】:
以上是关于iOS Card *card=[self.deck drawRandomCard];引起线程1:信号SIGABRT的主要内容,如果未能解决你的问题,请参考以下文章