1

我有一个填充列表的文本项列表。它的代码如下所示:

// CREATING EACH CELL IN THE LIST
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"business";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17];
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    }



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


    // CLOSE THE SPINNER
    [spinner stopAnimating];

    // return the cell for the table view
    return cell;
}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17];
    CGSize constraintSize = CGSizeMake(self.itemList.frame.size.width, MAXFLOAT);

    CGSize labelSize = [[cellTitleArray objectAtIndex:indexPath.row] sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 30;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    

}

我想做的是让这个人选择编辑每个项目。一种有意义的方法是使其成为一个 2 列列表,并在右侧列中创建一个类似“>”的字符,这样他们就可以点击它,它会给他们一个编辑项目的选项。

在这种情况下怎么做?

谢谢!

4

2 回答 2

2

要捕获一行,请单击:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Use indexPath.row to find your selection
    ...
}

如果您观看仅捕获一个按钮或类似的点击:

[self.buttono addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside];

如果您想使用accessoryType,您可以将此代码放在您的cellForRowAtIndexPath方法中。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Pick an indicator to suit your need/look
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

然后你像这样在点击上采取行动

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    // Perform action for this click on row indexPath.row
}

如果您indexPath.row不足以区分您的点击(我不明白为什么它不会!)那么您可以随时setTag在您的披露按钮上使用。

于 2012-12-14T22:39:55.670 回答
1
  [self.tableView indexPathForSelectedRow];

  [self.tableView indexPathForCell:sender]; //if you have a sender
于 2012-12-14T23:39:26.413 回答