1

ユーザーが前の画面から値を選択し、ナビゲーションコントローラーがそれらをポップバックした後、セル内のラベルを更新しようとしています(これはセルのラベルテキストではありません。セル内の別のカスタムラベルです)。

ただし、reloadData を呼び出すと、セル内のラベルが消去されて新しい値が配置される代わりに、実際には既に存在していたものの上にスタックされます。200 という数字の上に 50 を置いた場合のように。0 と 5 が重なり合った奇妙なメッシュが得られます。

これを調整する方法についてのアイデアはありますか?ビューが表示されるたびに、ラベルのテキストを "" にリセットする必要がありますか? もしそうなら、これを行う最良の方法は何ですか、cellForRowAtIndexPathメソッドで試しましたが、変更はありません。

cellforRowAtIndexPath コード

 // Set up the cell...
static NSString *CellIdentifier = @"Cell";

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

    // get the dictionary object
NSDictionary *dictionary = [_groups objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"key"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

//label for currently selected/saved object
_currentSetting = [[UILabel alloc] initWithFrame:CGRectMake(160, 8, 115, 25)];
[_currentSetting setFont:[UIFont systemFontOfSize:14]];
_currentSetting.backgroundColor = [UIColor clearColor];
_currentSetting.textColor = [UIColor blueColor];
_currentSetting.textAlignment = NSTextAlignmentRight;

_currentSetting.text = [NSString stringWithFormat:@""];
_currentSetting.text = [NSString stringWithFormat:@"%@ mi",[setting.val stringValue]];

 [cell.contentView addSubview:_currentSetting];

 return cell
4

2 に答える 2

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

    UILabel *customLabel;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,320,44)];
        customLabel.tag = 123;
        [cell addSubview:customLabel];
    } else {
        customLabel = (UILabel *)[cell viewWithTag:123];
    }

    customLabel.text = @"Some nice text";

    return cell;
}
于 2013-01-31T15:03:02.673 に答える