如果UITableView中某一行不允许点击变蓝色如何设置?

要在cellForRowAtIndexPath的代理方法中,对应的cell加入 cell.selectionStyle = UITableViewCellSelectionStyleNone;

下面是我的开发代码,进攻参考

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

{

    if (indexPath.section == 0) {

        static NSString *TableViewCell = @"TableViewCell"

        UITableViewCell *cell = [tableView

                                 dequeueReusableCellWithIdentifier: TableViewCell]; 

        if (cell == nil) { 

            cell = [[[UITableViewCell alloc

                     initWithStyle:UITableViewCellStyleDefault

                     reuseIdentifier: TableViewCell] autorelease]; 

        } 

        

        NSUInteger row = [indexPath row]; 

        NSString *title = [nameList objectAtIndex:row];

        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 42)];

        [label setText:title];

        [label setBackgroundColor:[UIColorclearColor]];

        [cell.contentView addSubview:label];

        if (row==0) {

            //user name

            if (mNameField == NULL) {

                UITextField *content = [[UITextField alloc]initWithFrame:CGRectMake(90, 10, 220, 30)];

                [content setBackgroundColor:[UIColor clearColor]];

                self.mNameField = content;

                [content release];

            }

            [cell.contentView addSubview:mNameField];

        }else if ( row == 1){

            //password

            if (mPasswordField == NULL) {

                UITextField *content = [[UITextField alloc]initWithFrame:CGRectMake(90, 10, 220, 30)];

                [content setBackgroundColor:[UIColor clearColor]];

                content.secureTextEntry = YES;

                self.mPasswordField = content;

                [content release];

            }

            [cell.contentView addSubview:mPasswordField];

        }else if(row == 2){

            //password confirm

            if (mPasswordConfirmField == NULL) {

                UITextField *content = [[UITextField alloc]initWithFrame:CGRectMake(90, 10, 220, 30)];

                [content setBackgroundColor:[UIColor clearColor]];

                content.secureTextEntry = YES;

                self.mPasswordConfirmField = content;

                [content release];

            }

            [cell.contentView addSubview:mPasswordConfirmField];

        }

        

        [label release];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell; 

    }

    returnnil;

}

posted on 2012-08-28 10:48  刚冲出起跑线的人  阅读(3231)  评论(0编辑  收藏  举报

导航