0

我正在 xcode 中编写一个简单的应用程序,但是每当我尝试在模拟器中运行该应用程序时,我都会得到以下信息:

Thread 1: Signal SIGABRT
libc++abi.dylib: terminate called throwing an exception
(lldb) 

它在第 25 行的 applicationDidFinishLaunchingWithOptions 处崩溃:[self.window makeKeyAndVisible];

我的代码:

- (IBAction)handleTap:(UITapGestureRecognizer *)recognizer {
    NSArray * entre = @[ @"Indian", @"American", @"Chinise", @"Italien", @"Japenese", @"Barbeque", @"Breakfast", @"Pizza" ];
    NSArray * dessert = @[ @"Ice Cream", @"Cake", @"Pie", @"Gelato", @"Cupcakes"];
    NSInteger r = arc4random()%8;
     NSInteger f = arc4random()%4;
    switch (segmentedControl.selectedSegmentIndex) {
        case 0:

            [label setText:[NSString stringWithFormat: entre[r]]];
            break;
        case 1:

            [label setText: [NSString stringWithFormat: dessert[f]]];
        default:
            break;
    }
}
4

1 回答 1

-1

那么这里的问题是你得到一个随机数 r ,它的值可以是 0-8 并且 entre[8] 在数组范围之外。甜点也一样[f]

尝试

NSInteger r = arc4random()%7;
NSInteger f = arc4random()%3;
于 2013-07-23T05:17:34.957 回答