【问题标题】:int not increasing [closed]int不增加[关闭]
【发布时间】:2012-01-27 04:43:37
【问题描述】:

我在一个被多次调用的方法中有一个嵌套嵌套(双嵌套)的 if 语句。每次我在 if 语句中的 int (count) 中加一。在这里:

      if (currentString) {

            count += 1;
            NSLog(@"%i" , count);
        }

我记录了它,它记录了几次,但数字总是 1:

    2012-01-27 12:29:26.127 Appletini[479:10a03] 1
   2012-01-27 12:29:26.128 Appletini[479:10a03] 1       
   2012-01-27 12:29:26.132 Appletini[479:10a03] 1
   2012-01-27 12:29:26.134 Appletini[479:10a03] 1
    2012-01-27 12:29:26.138 Appletini[479:10a03] 1
  2012-01-27 12:29:26.139 Appletini[479:10a03] 1
   2012-01-27 12:29:26.143 Appletini[479:10a03] 1
    2012-01-27 12:29:26.143 Appletini[479:10a03] 1

count 是一个实例变量:

 @interface RSSItem : NSObject <NSXMLParserDelegate> {

   int count;

}

有什么想法吗???

【问题讨论】:

  • 您的代码不足以查找原因。尝试提供更多代码。
  • yes... 显示在哪里声明 count 以及如何调用该方法。

标签: objective-c c if-statement int


【解决方案1】:

count 可能是该方法的本地。也许您打算将count 设为实例变量?无论如何——如果你想要更具体的回应,更多的代码会有所帮助。

【讨论】:

  • 是的,它是一个实例变量
【解决方案2】:

我的猜测是你的意思是让“count”成为static,所以它保留了它的值,但是你忘记了它只是一个普通的局部变量。

【讨论】:

  • 谢谢你我把静态整数计数;在我的实现文件中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
  • 2021-09-06
相关资源
最近更新 更多