我是新的IOS,我想知道如何在时间上保存NSMutableArray计数母猪我可以与新计数进行比较吗?
我在应用程序上添加带有计数的徽章图标,当我点击新行时删除,但是当我刷新并添加新行时,再次添加所有徽章。
这是代码:
- (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)];
}
}
感谢
答案 0 :(得分:0)
您的设计不是很好。永远不要那样做。 应用程序徽章编号不用于存储用户数据,而是用于向用户提供视觉指示。
您需要使用临时变量。
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;
}
}
答案 1 :(得分:0)
[[NSUserDefaults standardUserDefaults] setInteger:nombre forKey:@"MaxCount"];
[[NSUserDefaults standardUserDefaults] synchronize]
//以上代码用于保存......
并且为了重新获得这个最大数量,您可以在下面的代码中写下您想要我的朋友
NSInteger getMax1=[[NSUserDefaults standardUserDefaults] integerForKey:@"MaxCount"];//This is for getting stored max count...
让我知道它的工作与否......
快乐编码...... !!!