【问题标题】:Button is creating error upon adding of image view添加图像视图时按钮创建错误
【发布时间】:2013-03-04 14:06:15
【问题描述】:

每当我单击旋转时,它都会生成此错误并使应用程序崩溃。在我上传图像视图之前,该应用程序运行良好并且旋转很棒。我知道代码可能告诉我出了什么问题,但我无法理解这一点。

下面用粗体表示的是它的生成

- (IBAction)spinAction:(id)sender {

    [_chosenComponents removeAllObjects];
    for (int i = 0; i < _componentsInPicker.count; i++) {
        int randNum = arc4random() % [self.theSlotPicker numberOfRowsInComponent:i];

        [_theSlotPicker selectRow:randNum inComponent: i animated:YES];
        [_chosenComponents addObject:
         [NSNumber numberWithInt:[(NSArray *)[_baseList objectAtIndex:i] indexOfObject:[(NSArray *)[_componentsInPicker objectAtIndex:i] objectAtIndex:randNum]]]];
    }
    NSLog(@"%@", _chosenComponents);

按下按钮后吐出/崩溃“线程 1:EXC_ARITHMETIC (code=EXC_1386_DIV,subcode=0x0)”

如果可以,请指导我如何解决此错误。

谢谢!


输出错误:(lldb)

【问题讨论】:

  • 请将应用程序吐出的错误消息发布到 xcode 的输出窗口。
  • 将 **** 放在代码块中不会使它们变粗。将错误分开放置,以便其他人注意到。
  • 好吧,很抱歉这个更新。下面没有这样的运气。在添加 UIImageView 之前,它就像一个魅力。
  • @user2175105: 尝试记录 [self.theSlotPicker numberOfRowsInComponent:i];循环内。找出它发生在哪个迭代上。还要登录 self.theSlotPicker 看看是否为 nil?

标签: iphone ios xcode uiimageview uibutton


【解决方案1】:

出现此错误可能是因为您在使用arc4random() % ..... 时发生被零除

不要使用arc4random() % n,而是使用arc4random_uniform(n)。它将返回一个 0 到 n 范围内的数字。

然而这并不能解决固有的问题

[self.theSlotPicker numberOfRowsInComponent:i] 在某个时间点返回零。

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    相关资源
    最近更新 更多