2012-04-02 3 views
-4

У меня есть проект, в котором я хочу отключить ячейки UITableView в начале при загрузке представления, и после нажатия кнопки ячейки UITableView должны быть включены и должны работать должным образом.Как включить или отключить ячейки в uitableview

Как это сделать?

+0

Пожалуйста, проясните, что вы подразумеваете под этим вопросом, они должны выглядеть включенными и отключенными? – Armand

ответ

8

Вы можете использовать table.allowsSelection = NO; в вашем режиме viewwillappear, а затем сделайте это YES onbutton click event.

1
//In UIButton pressed event 
boolEnabled=YES; //Declare it in header file 
[yourTableView reloadData]; //reload UITableView 

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

     //After creating a cell 

     if(boolEnabled==YES) //Will enable for any action 
     { 
      cell.userInteractionEnabled=YES; 
     } 
     else 
     { //disable for any action 
     cell.userInteractionEnabled=NO; //Default boolEnabled=NO; 
     }  
} 
+0

Существует еще одно свойство 'cell.enable', которое вы также можете установить на' YES' или 'NO'. – Hemang

2

Если вы хотите, чтобы сделать весь стол Отключено то и можно использовать:

table.userInteractionEnabled = FALSE; 

А затем нажмите на кнопку:

table.userInteractionEnabled = TRUE; 
1

Что я хотел бы сделать, это иметь @property (nonatomic) BOOL tableIsActive

В моем - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath Я бы сделал

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(self.tableIsActive) 
    { 
     //style cells for enabled table 
    } 
    else 
    { 
     //style cells for enabled table 
    } 
} 

А потом в моей - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath я бы

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(self.tableIsActive) 
    { 
     //handle selection 
    } 
    else 
    { 
     [tableView deselectRowAtIndexPath:indexPath animated:NO]; 
    } 
} 

И тогда я бы функцию -(void) enableTable:(id)sender, которую я связываться с моей кнопки, что делает

-(void) enableTable:(id)sender 
{ 
    if(self.tableIsActive) 
     self.tableIsActive = NO; 
    else 
     self.tableIsActive = YES; 
} 

И затем после включения вызова [yourTable reloadData];

0

Вы можете сделать это, используя приведенный ниже код, Просто проверьте состояние TableView delgate method

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

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

    //Way to stop to choose the cell selection 
    if(indexpath.row==0) 
     { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     Or 
     cell.userIneractionEnabled=False; 
     } 
     //while rest of the cells will remain active, i.e Touchable 

    return cell; 

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