系统自带的 pickerView,假如我现在给的datasource 为1--60 的数,在pickerview中,假设 滚轮上小于18的数(行),不能点击(不参与交互),大于或者等于的正常使用。
在tableview中可以这样
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      ...............
..............
        if (indexPath.row < 18) {
            cell.userInteractionEnabled = NO;
        }
...............
...............
  }
有类似的实现吗?

解决方案 »

  1.   

    你的代码是UITableView的,但问题是UIPickerView的,问的是哪一种呢?
    如果是UITableView,则使用下面代码即可:- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row>=18) {
             // Do user interactions
        }
    }
      

  2.   

    如果想要更完美的交互效果,需要将cell的selectionStyle设置为UITableViewCellSelectionStyleNone- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
            if (indexPath.row < 18)  {
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            else {
                cell.selectionStyle = UITableViewCelLSelectionStyleDefault;
            }
    }
    或者,进行一些特殊的定制,例如将cell的backgroundColor设置为lightGray
      

  3.   

    回复一楼的,我要的是pickerview的,想把问题说明白点,所以引用了tableview。