-2

私は新しい 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)];
}

}

感謝

4

2 に答える 2

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;
    }

}
于 2013-01-02T06:06:45.307 に答える
0
[[NSUserDefaults standardUserDefaults] setInteger:nombre forKey:@"MaxCount"];
[[NSUserDefaults standardUserDefaults] synchronize]

// 上記のコードは保存用です...

そして、この最大数を取得するために、私の友人が欲しい場所にコードの下に書くことができます

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

それが機能しているかどうかを教えてください...

ハッピーコーディング...!!!

于 2013-01-02T06:07:37.460 に答える