如何在tableView&中存储数据下次更新 [英] How to store data in the tableView & update it next time

查看:54
本文介绍了如何在tableView&中存储数据下次更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是用我的名字添加游戏得分的代码.

This is the code to add my score of the game with name.

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

这是存储名称&玩家的分数,但每次在表中仅显示一条记录.

This is storing name & score of the player but each time it displays only one record in the table.

它必须显示列表中的前十名得分.

It must show the last top ten scores in the list.

主要问题是这没有存储&显示每个分数数据.

Main problem is that this is not storing & showing every score data.

请指导我解决此问题.

谢谢.

推荐答案

您不能使用表视图来存储数据.表格视图是一个UI元素,可用于显示数据. UITableView参考.要存储数据,您可以使用:

You cannot use table view for storing data. Table view is an UI Element which can be used for display your data. UITableView reference. For storing data you can use:

  1. 核心数据
  2. Sqlite
  3. Plist

这篇关于如何在tableView&amp;中存储数据下次更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆