ios - indexPath 在所有行中返回 0

标签 ios objective-c uitableview

我创建了一个只有 1 个部分的 tableView,它在所有 indexPath.Row 中一直返回 0。我究竟做错了什么?这是我记录 indexPath

NSLog(@"%@", indexPath);

<NSIndexPath: 0xd2897d0> {length = 2, path = 0 - 0}
<NSIndexPath: 0xd290af0> {length = 2, path = 1 - 0}
<NSIndexPath: 0xd2a5cd0> {length = 2, path = 2 - 0}
<NSIndexPath: 0xd2a8340> {length = 2, path = 3 - 0}

cellForRowAtIndexPath

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



    UITableViewCell *cell = nil;


    if (indexPath.row < 3) {
        TextFieldTableViewCell *accountCell = [tableView dequeueReusableCellWithIdentifier: textFieldCellIdentifier forIndexPath: indexPath];
        accountCell.cellTextField.delegate = self;

            accountCell.cellLabel.text = [accountArray objectAtIndex: indexPath.row];
        if (indexPath.row == 0) {


        accountCell.cellTextField.keyboardType = UIKeyboardTypeDefault;
        } else if (indexPath.row == 1) {


            accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
        } else if (indexPath.row == 2) {


            accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
        }

        cell = accountCell;


    } else if (indexPath.row == 3) {

        ACEExpandableTextCell *textViewCell = [tableView expandableTextCellWithId:@"cellId"];
        textViewCell.text = [self.cellData objectAtIndex:indexPath.section];
        textViewCell.textView.placeholder = @"Placeholder";
        cell = textViewCell;

    }


    return cell;
}

最佳答案

可能是这个问题

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [arry count];
}   
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    return 1;
    }

代替

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    return [arry count];
    }

关于ios - indexPath 在所有行中返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25160152/

相关文章:

ios - 如何以编程方式更改锚定样式约束?

ios - AVAssetReaderTrackOutput 卡在 copyNextSampleBuffer 上

ios - 按日期获取最后 25 个 CoreData 条目

objective-c - 需要在iPad中添加popovercontroller

iOS 9 崩溃 - 无法识别的选择器发送到实例;选择器是有效的属性

ios - 如何配置UITableViewCell以隐藏其控件并显示人字形?

ios - 嵌入在 UITableViewCell 中的动态、自定义布局 UICollectionView

ios - 如何保存或存储 SKPayment 交易?

iOS裁剪相机拍摄的图像

ios - 如何获取表当前所有行信息