iphone - 没有可见的@interfacefor 'NSNumber' 声明选择器 initwithInt。错误

标签 iphone ios objective-c

我正在制作一个包含多个不同类别的测验应用程序。我还有一些事情要做,但我遇到了标题中的错误。这是我的代码到目前为止的样子

-(IBAction)Category1:(id)sender{

    Category1.hidden = YES;
    Category2.hidden = YES;
    Question.hidden = NO;

    Answer1.hidden = NO;
    Answer2.hidden = NO;
    Answer3.hidden = NO;
    Answer4.hidden = NO;

    Right1.hidden = YES;
    Right2.hidden = YES;
    Right3.hidden = YES;
    Right4.hidden = YES;

    Wrong1.hidden = YES;
    Wrong2.hidden = YES;
    Wrong3.hidden = YES;
    Wrong4.hidden = YES;

    SelectCategory.hidden = YES;

    NSMutableArray *questionArray = [[NSMUTABLEArray alloc] init];
    for (int i = 1; i < 101; i++) {
        [questionArray addObject:[NSNumber alloc] initwithInt:i]];  // Here is where the error occurs
    }

    for (int i = 0; i < 100; i++) {

        int randomIndex = arc4random() % [questionArray count];
        int Category1Question = [[questionArray objectAtIndex:randomIndex] intValue];
        [questionArray removeObjectAtIndex:randomIndex];
        switch (Category1Question) {
            case 0:
            Question.text = [NSString stringWithFormat:@"Question here"];
            Right1.hidden = NO;
            Wrong2.hidden = NO;
            Wrong3.hidden = NO;
            Wrong4.hidden = NO;
            Answer1.text = [NSString stringWithFormat:@"Correct answer here"];
            Answer2.text = [NSString stringWithFormat:@"Wrong answer here"];
            Answer3.text = [NSString stringWithFormat:@"Wrong answer here"];
            Answer4.text = [NSString stringWithFormat:@"Wrong answer here"];
            break;
            case 1:
            // etc etc all the way to case 99

           default:
               break;
        }
    }
}

我完全想不通。如果有人可以帮助并向我解释,我将非常感激。谢谢

最佳答案

没有initwithInt:但是有initWithInt:,Objective-C区分大小写。

而你的 [ 放错了:

 [questionArray addObject:[NSNumber alloc] initwithInt:i]]; 

应该是:

 [questionArray addObject:[[NSNumber alloc] initWithInt:i]]; 

或者更好:

 [questionArray addObject:[NSNumber numberWithInt:i]]; 

关于iphone - 没有可见的@interfacefor 'NSNumber' 声明选择器 initwithInt。错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18083560/

相关文章:

iphone - 如何在不知道编码的情况下读取文本文件

ios - XCUITest、UIDatePicker、adjustToPickerWheelValue

ios - 测试 VoiceOver : how can I verify that my UIAccessibilityLayoutChangedNotification notifications are working?

android - phonegap 构建应用程序的 Manifest.xml 和 config.xml 之间的区别

iphone - 对从 pList 加载的 UITableView 部分进行排序

ios - UITableView 优于 UITableViewCell didSelectMethod

ios - 使用 SDWebImage 处理超大图像的下载

ios - 如何管理 ios ARC 项目中的内存分配问题

iphone - 使用 Quartz CGContextFillEllipseInRect 绘制两个圆

objective-c - 如果应用程序启动时没有打开文档,如何在启动时显示欢迎屏幕?