2015-01-28 8 views
1

Здесь есть и другие подобные вопросы, но никто из них не отвечает на то, что я ищу.Добавить подробный текст на этикетке пользовательского UITableViewCell

У меня есть экран настроек, который должен выглядеть следующим образом:

enter image description here

Я добавил новый UITableViewCell класса и подключил его к главному столу с этим кодом:

static NSString *cellIdentifier = @"settingCellIdentifier"; 
SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (cell == nil){ 

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SettingsTableViewCell" owner:self options:nil]; 
    cell = [nib objectAtIndex:0]; 
} 

Я знаю, что мы установить стиль таблицы в UITableViewCellStyleSubtitle, чтобы добавить подробный текст, но единственный способ, который я знаю, это сделать:

cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:SimpleTableIdentifier]; 

Я не могу использовать этот код в своем случае.

В настоящее время я использую две метки, и он принес следующий беспорядок:

enter image description here

Далее следует cellForRowAtIndexPath код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
static NSString *cellIdentifier = @"settingCellIdentifier"; 
SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (cell == nil){ 

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SettingsTableViewCell" owner:self options:nil]; 
    cell = [nib objectAtIndex:0]; 
} 

NSInteger row = indexPath.row; 


switch (row) { 
    case 0: 
     cell.settingLabel.text = @"Settings"; 
     cell.subText.text = @""; 
     break; 
    case 1: 
     cell.settingLabel.text = @"Account Info"; 
     cell.subText.text = @"Display your Home Business account information"; 
     break; 
    case 2: 
     cell.settingLabel.text = @"Sign Out"; 
     cell.subText.text = @"Signed in as "; 
     break; 
    case 3: 
     cell.settingLabel.text = @"Send Feedback"; 
     cell.subText.text = @"Send comments, requests or error reports to Home Business"; 
     break; 
    case 4: 
     cell.settingLabel.text = @"Terms of User"; 
     cell.subText.text = @""; 
     break; 
    case 5: 
     cell.settingLabel.text = @"Privacy Policy"; 
     cell.subText.text = @"Your privacy and security are our top priorities"; 
     break; 
    case 6: 
     cell.settingLabel.text = @"Like us on Facebook"; 
     cell.subText.text = @""; 
     break; 
    case 7: 
     cell.settingLabel.text = @"Follow us on Twitter"; 
     cell.subText.text = @""; 
     break; 
    case 8: 
     cell.settingLabel.text = @"About Us"; 
     cell.subText.text = @""; 
     break; 

    default: 
     break; 
} 

return cell; 
} 

Мне нужно знать, как я могу добавить детали текст с одной меткой.

+0

Перейти к пользовательской табличной ячейке, почему у вас есть какая-либо конкретная потребность? – Spynet

+0

Показать код, в котором вы заполняете ярлыки. –

+0

i AM используя пользовательскую таблицу вида таблицы. Нужно знать, как я могу добавить текст детали для ярлыка. –

ответ

1

Зачем вам нужна специальная ячейка? Просто используйте обычную ячейку tableview и ее textLabel & detailTextLabel. Это послужит вашим потребностям. Вы даже можете установить количество строк для detailTextLabel. Попробуйте следующее:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 
    } 
    if (indexPath.row == 0) { 
     cell.textLabel.text = @"Profile"; 
     cell.detailTextLabel.text = @"Lorem ipsum dolor sit amet, vix id debet libris. Quem oblique blandit ne vix, repudiare prodesset an mel. At libris tacimates accusata has, eum at ignota cotidieque. Pro malorum nominati ei."; 
    } 
    else if (indexPath.row == 1){ 
     cell.textLabel.text = @"Server"; 
     cell.detailTextLabel.text = @"Lorem ipsum dolor sit amet, vix id debet libris. Quem oblique blandit ne vix, repudiare prodesset an mel. At libris tacimates accusata has, eum at ignota cotidieque. Pro malorum nominati ei."; 
    } 
    else if (indexPath.row == 2){ 
     cell.textLabel.text = @"Security"; 
     cell.detailTextLabel.text = @"Lorem ipsum dolor sit amet, vix id debet libris. Quem oblique blandit ne vix, repudiare prodesset an mel. At libris tacimates accusata has, eum at ignota cotidieque. Pro malorum nominati ei."; 
    } 
    else if (indexPath.row == 3){ 
     cell.textLabel.text = @"Forget Password"; 
     cell.detailTextLabel.text = @"Lorem ipsum dolor sit amet, vix id debet libris. Quem oblique blandit ne vix, repudiare prodesset an mel. At libris tacimates accusata has, eum at ignota cotidieque. Pro malorum nominati ei."; 
    } 
    else if (indexPath.row == 4){ 
     cell.textLabel.text = @"About"; 
     cell.detailTextLabel.text = @"Lorem ipsum dolor sit amet, vix id debet libris. Quem oblique blandit ne vix, repudiare prodesset an mel. At libris tacimates accusata has, eum at ignota cotidieque. Pro malorum nominati ei."; 
    } 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.backgroundColor = [UIColor clearColor]; 
    return cell; 
+0

Это то, что все предложили, и поэтому я сделал это так. Спасибо. –

Смежные вопросы