2012-04-02 19 views
-4

ビューが読み込まれたときにUITableViewのセルを無効にしたいプロジェクトがあり、ボタンを押した後にUITableViewのセルを有効にする必要があります。正しく機能します。uitableviewでセルを有効または無効にする方法

どうすればいいですか?

+0

有効にして無効にする必要があるということを明確にしてください。 – Armand

答えて

8

table.allowsSelection = NO;あなたのviewwillappearメソッドの をクリックし、YESボタンをクリックします。

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

あなたがテーブル全体の無効にしたい場合は、uを使用することができます。

table.userInteractionEnabled = FALSE; 

、[OK]をクリックします上のボタン上:私はどうなるのか

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 I

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

だろう。そして、私は、コール[yourTable reloadData];

を有効にした後、その後

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

としない、私のボタンにバインドする機能-(void) enableTable:(id)senderを持っているでしょう

0

あなたは次のコードを使用してそれを行うことができます。テーブルビューのデルゲートメソッド

- (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; 

} 
関連する問題