开发者

How to disable the selection of individual cells of the UITableView?

Once the user taps a cell triggering an action, I want to disable the user interaction and then reenable 开发者_Go百科user interaction when the action has finished. Can someone tell me how to do this?


Just check for the condition in TableView delegate 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.userInteractionEnabled=False;
     }
     //while rest of the cells will remain active, i.e Touchable

    return cell;

}


Just add a BOOL variable that you set to true when the action has started. Then implement the -[tableView:willSelectRowAtIndexPath:] method of the tableview's delegate so that it returns nil when the variable is currently true for that index path.


or you can make the selectionStyle when action is running

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜