nsxmlparse Tableview Alignment - PullRequest
       2

nsxmlparse Tableview Alignment

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

alt textalt text статическая строка NSString * CellIdentifier = @ "Cell";

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease];
}
cell.backgroundView = [[[CustomCell alloc] init] autorelease];
cell.selectedBackgroundView = [[[CustomCell alloc] init] autorelease];

// At end of function, right before return cell:
cell.textLabel.backgroundColor = [UIColor clearColor];


// Configure the cell.
UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 45)];
UILabel *myLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(5, 55, 300, 20)];
UILabel *myLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 68, 300, 60)];

Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];

    myLabel1.text=aBook.title;
    myLabel2.text=aBook.pubDate;
    myLabel3.text=aBook.description;


//myLabel1.lineBreakMode=UILineBreakModeCharacterWrap;
myLabel1.lineBreakMode=UILineBreakModeWordWrap;
myLabel1.numberOfLines=1;
myLabel1.textColor=[UIColor redColor];
myLabel1.backgroundColor = [UIColor blueColor];
myLabel1.font=[UIFont systemFontOfSize:14];

myLabel2.font=[UIFont systemFontOfSize:12];

myLabel3.textAlignment=UITextAlignmentLeft;
myLabel3.textColor=[UIColor blueColor];
myLabel3.lineBreakMode=UILineBreakModeCharacterWrap;
myLabel3.numberOfLines=3;
//myLabel3.lineBreakMode=UILineBreakModeWordWrap;
myLabel3.lineBreakMode=UILineBreakModeTailTruncation;
myLabel3.font=[UIFont systemFontOfSize:14];



//myLabel1.shadowColor=[UIColor redColor];
//myLabel1.backgroundColor=[UIColor grayColor];
        [cell.contentView addSubview:myLabel1];
        [cell.contentView addSubview:myLabel2];
        [cell.contentView addSubview:myLabel3];




    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[myLabel1 release];
[myLabel2 release];
[myLabel3 release];
//Set up the cell

return cell;

ребята, у меня есть эти кодировки. в mylabel 1, если я установил на 2, текст уменьшается, поэтому я не вижу. теперь, наконец, я хочу отобразить 2 строки заголовка, 1 строку pubDate и 3 строки описания в одной строке. я отобразил, но мне нужно выравнивание, то есть выше точек, он должен удалить теги HTML (& mdash)

Я не знаю, как это настроить. Борьба с этим. Пожалуйста, помогите мне

1 Ответ

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

Создайте подкласс UITableViewCell и используйте эту пользовательскую ячейку.

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

Вторая проблема - это производительность каждый раз, когда вы выделяете init и выпускаете 3 метки в каждой строке.Это приведет к низкой скорости прокрутки на медленных устройствах, таких как iPhone 3G.

Взгляните на образец кода Apple CustomTableViewCell .

Здесь - учебное пособиеКак создать подкласс UITableViewCell
С пользовательским классом ячеек ваш метод будет выглядеть следующим образом

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    CustomTableViewCell *cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    [cell setLabel1String:aBook.title];
    [cell setLabel2String:aBook.pubDate];
    [cell setLabel3String:aBook.description];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

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