禁用NSArray UITableView中的单元格

禁用NSArray UITableView中的单元格,uitableview,nsarray,Uitableview,Nsarray,我正在加载一个tableview,希望将object 2和objet 4灰显,并使它们对用户交互禁用 我有 @property (nonatomic, strong) NSArray *list; m: - (void)viewDidLoad { [super viewDidLoad]; self.list = [[NSArray alloc] initWithObjects:@"Object 1", @"Object 2", @"Object 3

我正在加载一个tableview,希望将object 2和objet 4灰显,并使它们对用户交互禁用

我有

@property (nonatomic, strong) NSArray *list;
m:

  - (void)viewDidLoad
    {
        [super viewDidLoad];

        self.list = [[NSArray alloc] initWithObjects:@"Object 1", @"Object 2", @"Object 3", @"Object 4", @"Object 5", nil];


    }

我已经试着使用

object=[self.list objectAtIndex:2]来获取对象2,但它什么都不做


我该怎么做呢?

textlab
a
UILabel
还是
UITextField
?这个名字让我感到奇怪。假设它是一个
UILabel
,并且您想要阻止与单元格(以及其中的控件)的交互,您可以执行以下操作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


    cell.textLabel.text = [list objectAtIndex:[indexPath row]];


    if (indexPath.row == 1 || indexPath.row == 3) {
        cell.userInteractionEnabled = NO;
    } else {
        cell.userInteractionEnable = YES;
    }

    return cell;
}
或者你只是想阻止用户选择单元格?在这种情况下,您可能应该考虑重写<代码> TabelVIEW:WEB StReWATIDENXXPATH:<代码> > < UTababVIEW委托> <代码> ./P>
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1 || indexPath.row == 3) {
        return nil;
    return indexPath;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1 || indexPath.row == 3) {
        return nil;
    return indexPath;
}