0
-(IBAction)btnSaveScore:(id)sender
{
   if(!dictWinData)
      dictWinData = [[NSMutableDictionary alloc] init];


    array = [NSMutableArray arrayWithObjects:txt_EnterName.text,
                                             [NSString stringWithFormat:@"%i",iTap], nil];

    int increment = 0;

    NSLog(@"array data is:--> %@",array);

    for (int intWinData = 1; intWinData < [array count]; intWinData++)
    {
        [dictWinData setObject:array forKey:[NSString stringWithFormat:@"NameScore%d",increment]];
        increment++;
    }
}

これは、ゲームの私のスコアを名前で追加するコードです。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dictWinData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        ArrStr = [dictWinData valueForKey:[NSString stringWithFormat:@"NameScore%d",indexPath.row]];
        UILabel *lblDayName = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 160, 21)];
        lblDayName.text = [ArrStr objectAtIndex:0];
        lblDayName.textColor = [UIColor blackColor];
        lblDayName.font = [UIFont boldSystemFontOfSize:17.0];
        lblDayName.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:lblDayName];
        [lblDayName release];

        UILabel *lblLow = [[UILabel alloc] initWithFrame:CGRectMake(180, 50, 40, 21)];
        lblLow.text = [ArrStr objectAtIndex:1];
        lblLow.textColor = [UIColor blackColor];
        lblLow.font = [UIFont boldSystemFontOfSize:17.0];
        lblLow.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:lblLow];
        [lblLow release];
    }
return cell;
}

これはプレーヤーの名前とスコアを保存していますが、毎回テーブルに 1 つのレコードのみを表示します。

リストの最後の上位 10 のスコアを表示する必要があります。

主な問題は、これがすべてのスコアデータを保存および表示していないことです。

この問題を解決するために私を導いてください。

前もって感謝します。

4

2 に答える 2

2

特定のタグを使用してそのコントロールを取得し、それにテキストを割り当てるために必要な条件UITableViewの内外で表示するすべてのコントロールのタグを指定する必要があります。cell==nil

于 2012-10-10T10:28:06.763 に答える
1

テーブル ビューを使用してデータを保存することはできません。テーブル ビューは、データの表示に使用できる UI 要素です。UITableView 参照。データの保存には、次を使用できます。

  1. コアデータ
  2. スクライト
  3. プリスト
于 2012-07-20T17:09:37.533 に答える