如何在tableView&中存储数据下次更新它

时间:2012-07-20 14:33:50

标签: iphone

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

这是存储名称&amp;玩家的得分,但每次只显示表中的一条记录。

它必须显示列表中的最后十个分数。

主要问题是这不是存储&amp;显示每个得分数据。

请指导我解决这个问题。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您需要为UITableViewcell==nil条件之外的每个控件提供标记,以便使用特定标记检索该控件,然后提供文本分配它。

答案 1 :(得分:1)

您无法使用表格视图存储数据。表视图是一个UI元素,可用于显示数据。 UITableView reference。 要存储数据,您可以使用:

  1. Core data
  2. Sqlite
  3. Plist