【问题标题】:How Save Temporally NSMutableArray count? [closed]如何暂时保存 NSMutableArray 计数? [关闭]
【发布时间】:2013-01-02 06:03:34
【问题描述】:

我是新的IOS,我想知道如何暂时保存NSMutableArray计数sow我可以与新计数比较?

我在应用程序上添加了带有计数的徽章图标,并在我单击新行时删除,但是当我刷新并添加新行时,再次添加所有徽章。

这是代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:self.parseResults.count];

return self.parseResults.count;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


NSInteger badge = [[UIApplication sharedApplication] applicationIconBadgeNumber];


if (badge > 0) {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:(badge - 1)];
}

}

谢谢

【问题讨论】:

  • int tempCount = [数组计数];

标签: iphone ipad sdk ios6


【解决方案1】:
[[NSUserDefaults standardUserDefaults] setInteger:nombre forKey:@"MaxCount"];
[[NSUserDefaults standardUserDefaults] synchronize]

//以上代码用于保存...

为了找回这个最大计数,你可以在下面写下你想要我朋友的代码

 NSInteger getMax1=[[NSUserDefaults standardUserDefaults] integerForKey:@"MaxCount"];//This is for getting stored max count...

让我知道它是否有效...

编码愉快...!!!

【讨论】:

    【解决方案2】:

    你的设计不是很好。永远不要那样做。 应用徽章编号不是用来存储用户数据的,它是用来给用户的视觉指示的。

    您需要使用临时变量。

    int tempCount  = 0;
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    
       tempCount = self.parseResults.count;
    
       return self.parseResults.count;
    
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (tempCount > 0)
        {
           tempCount -=1;
        }
    
    }
    

    【讨论】:

    • 谢谢,我更改了临时变量
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    相关资源
    最近更新 更多