2013-09-04 2 views
0

Я пытался скрыть свою detailTextLabel.cell в то время как мои Tableview нагрузок, кодом,скрытие/показ detailTextLabel в UITableView

cell.textLabel.text=[array objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row]; 

cell.detailTextLabel.hidden = YES; 

При выборе строки, попытайтесь отобразить detailarray в didSelectRowAtIndexPath, как и ожидалось detailarray отображает в то время как я нажав на строку и один раз я остановить, нажав его, detailarray текст исчезает, почему это происходит так,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
NSLog(@"indexpath is %d", indexPath.row); 
selectedIndex = indexPath.row; 
isSearching = YES; 

[self.tableview beginUpdates]; 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

cell.textLabel.text=[dealarray objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row]; 

cell.detailTextLabel.hidden = NO; 


[self.tableview endUpdates]; 



} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (isSearching && indexPath.row == selectedIndex) 
{ 

    return 77; 

} 
return 44; 


} 

Редакцией:

Assigned переменной «а» в файл .h и использовал код следующим образом,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
// Configure the cell... 
cell.textLabel.text=[dealarray objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row]; 
    NSLog(@"dealarray %@\n %@",dealarray,detailarray); 

    if (a==-1) { 
     cell.detailTextLabel.hidden = YES; 

    } 
    else if(a==indexPath.row) 
    { 
     cell.detailTextLabel.hidden = NO; 
       } 
    else cell.detailTextLabel.hidden = YES; 

return cell; 


} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
NSLog(@"indexpath is %d", indexPath.row); 
selectedIndex = indexPath.row; 
isSearching = YES; 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

cell.textLabel.text=[dealarray objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row]; 
a=indexPath.row; 
[tableview reloadData]; 

}

+0

Вам нужно показать detailLabelText, появляющийся после нажатия также ??? –

+0

@NeelamVerma, я должен показать detailLabelText только после его нажатия, потому что я ожидаю показать подробное объяснение относительно выбранной строки. – sathya

ответ

2

Для этого можно использовать два типа клеток.

Для нормальных данных используйте базовую ячейку. При выборе, перезагрузите таблицу или ячейку и используйте другую ячейку detailLabel только для выбранной строки.

И это решит вашу проблему.

Благодаря

0

Если я понял ваше требование, Вы можете попробовать ниже код, чтобы решить вашу цель.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 
(NSIndexPath *)indexPath { 
    /* . 

    Write necessary code here.... 
    */ 

    // ------------- 
    cell.textLabel.text=[array objectAtIndex:indexPath.row]; 
    if (![selectedRowIndexs containsObject:[NSNumber numberWithInt:indexPath.row]]) 
    { 
     cell.detailTextLabel.hidden = YES; 

    } 
    else 
    { 
     cell.detailTextLabel.hidden = NO; 

    } 

} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.detailTextLabel.text=[detailarray objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.hidden = NO; 
    if (![selectedRowIndexs containsObject:[NSNumber numberWithInt:indexPath.row]]) 
    { 
     [selectedRowIndexs addObject:[NSNumber numberWithInt:indexPath.row]]; 
    } 

} 
+0

спасибо за предложение, я сделал то же самое с помощью переменной инициализации .... – sathya

+0

thats ok then :) –