отображать два значения в одной и той же ячейке, один справа и второй слева от ячейки - PullRequest
0 голосов
/ 31 января 2011

я хочу отобразить два значения (одно - строка, а другое - целое число).
как показано ниже
строка1 00000 int1
строка2 00000 int2
строка3 00000 int3

0--> Пробелы

Я знаю, как отобразить 2 значения в одной и той же ячейке,
cell.textLabel.text = [NSString stringWithFormat: @ "% @ -% d", [splitArrayValue objectAtIndex: row],IntegerValue];

, но это выглядит примерно так:
string1 00 int1
string2 00000 int2
string3 000 int3
не в правильном выравнивании

я хочу отобразить это целочисленное значениево 2-м столбце в той же строке это возможно?

заранее спасибо

Ответы [ 2 ]

1 голос
/ 31 января 2011

Вы должны добавить два отдельных UILabels в клетку, дифференцируя их по тегу.

// tableView:cellForRowAtIndexPath
// ...
if (cell == nil) {
    cell = [[[UITableViewCEll alloc] init] autorelease];

    CGRect leftF = CGRectMake(10, 5, 100, 30);
    CGRect rightF = CGRectMake(120, 5, 100, 30);

    UILabel * left = [[[UILabel alloc] initWithFrame:leftF] autorelease];
    left.tag = kLeftLabel; // assumming #define kLeftLabel 100 

    [cell.contentView addSubview:left];

    UILabel * right = [[[UILabel alloc] initWithFrame:rightF] autorelease];
    right.tag = kRightLabel; // assumming #define kRightLabel 101 

    [cell.contentView addSubview:right];
}

UILabel * leftLabel = (UILabel*)[cell.contentView viewWIthTag:kLeftLabel];
UILabel * rightLabel = (UILabel*)[cell.contentView viewWIthTag:kRightLabel];

// now put your two values in these two distinct labels
0 голосов
/ 10 марта 2013

Вы также можете использовать приведенный ниже код. Надеюсь, что это может помочь.

Возьмите 2 изменяемых массива, скажем - массив1 и массив 2.

В viewDidLoad выделите массивы и сохраните значенияоба массива.

(void)viewDidLoad
{

    array1=[NsMutableArray alloc]init];
    [array1 addObject:@"string1"];
    [array1 addObject:@"string2"];
    [array1 addObject:@"string3"];

    array2=[NsMutableArray alloc]init];
    [array2 addObject:@"int1"];
    [array2 addObject:@"int2"];
    [array2 addObject:@"int3"];
}

Затем продолжите с кодом ниже в cellForRowAtIndexPath.

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath      *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2         reuseIdentifier:CellIdentifier] ;
    }

    cell.textLabel.text =[array1 objectAtIndex:indexPath.row];

    cell.detailTextLabel.text =[array2 objectAtIndex:IndexPath.row];

    return cell;

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...