ios-报错:'NSNumber' declares the selector initwithInt'

问题描述

报错:'NSNumber' declares the selector initwithInt'

做了一个不同类别的测试应用。代码运行后报错: No visible @interfacefor 'NSNumber' declares the selector initwithInt.'

代码:

-(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]];
时间: 2024-10-31 05:47:55

ios-报错:&amp;#39;NSNumber&amp;#39; declares the selector initwithInt&amp;#39;的相关文章

ionic emulate ios/run ios报错问题CDVViewController.h file not found.

xcode 8.0 在终端添加ios平台后,再执行 ionic emulate ios -l -c 结果编译失败,报错说 CDVViewController.h file not found. 然后去到处查试了各种方法,均无果.最后把平台删了重新添加居然就成功了-- 这里总结一下在各地搜寻到的解决这个问题的办法,每种解决办法都能解决一部分人的问题.但具体哪样对自己好使并不一定--以下供有同样问题的同行参考 -------------------------------------- 方法0:重新

iOS 真机测试的时候报错 After modifying system headers, please delete the module cache at &amp;#39;/ /Users/smile/Libr

这个是Xcode缓存导致的 fatal error: file ' '/ /Users/smile/Library/Developer/Xcode/DerivedData/ModuleCache/VE5HTVL861UA' was built  note: after modifying system headers, please delete the module cache at '/Users/ligang/Library/Developer/Xcode/DerivedData/Modu

ajax-关于callback(eval(&amp;amp;#39;(&amp;amp;#39;+xhr.responseText+&amp;amp;#39;)&amp;amp;#39;));IE报错的问题

问题描述 关于callback(eval('('+xhr.responseText+')'));IE报错的问题 //这是index.js的文件 (function() { var li = function(id) { return document.getElementById(id); }; li.init = function() {// li下的init方法 // 创建一个ajax对象并返回 try { return new XMLHttpRequest(); } catch (e) {

【c3p0】报错:java.io.FileNotFoundException: Resource not found at path &amp;#39;/mchange-log.properties&amp;#39;

  配置项目启动初始,报错如下: 1 java.io.FileNotFoundException: Resource not found at path '/mchange-commons.properties'. 2 at com.mchange.v2.cfg.BasicPropertiesConfigSource.propertiesFromSource(BasicPropertiesConfigSource.java:64) 3 at com.mchange.v2.cfg.BasicMul

torch7中require &amp;amp;#39;graphicsmagick&amp;amp;#39;报错

问题描述 torch7中require 'graphicsmagick'报错 在torch7中用luarocks install graphicsmagick ,安装成功.但是在require 'graphicsmagick'时报错,报错如下: ...ing/torch/install/share/lua/5.1/graphicsmagick/Image.lua:304: libGraphicsMagickWand.so: cannot open shared object file: No s

代码-spring报错 mismatched input &amp;amp;#39;gt&amp;amp;#39; expecting EOF

问题描述 spring报错 mismatched input 'gt' expecting EOF 代码如下: <?xml version="1.0" encoding="UTF-8"?> xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util

mongoDB报错Cannot find module &amp;#39;../build/Release/bson&amp;#39;

打算用nodejs写一个blog系统,发现nodejs还是存在很多的坑.在使用mongodb时遇到如下报错问题: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version 折腾了一番,最后是这样解决的: 找到 npm 的module mongodb ..node_

express-为什么在ejs模板使用&amp;amp;lt;%= img_tag(&amp;amp;#39;/images/a.jpg&amp;amp;#39;) %&amp;amp;gt;报错?

问题描述 为什么在ejs模板使用<%= img_tag('/images/a.jpg') %>报错? 为什么在ejs模板使用<%= img_tag('/images/a.jpg') %>时会img_tag is not defined? 解决方案 img_tag在哪里定义的,先要包含库进来

java eclipse-为什么报错 Duplicate entry &amp;amp;#39;2013-10-12 21:36:35&amp;amp;#39; for key 1

问题描述 为什么报错 Duplicate entry '2013-10-12 21:36:35' for key 1 我用一个数组记录先JTABLE单元格的横纵坐标,根据横纵坐标得知单元格中要修改的值,完后用for循环使用UPDATA语句依次更新数据库中其对应的单元格的值,为什么会报错Duplicate entry '2013-10-12 21:36:35' for key 1 该如何更改?