如何使用附件视图复选标记从UITableview单元格获取多个值?

时间:2011-12-11 12:39:30

标签: iphone

Ha ii每个人,我使用附件视图复选标记从UITableview单元格中选择多个值,我将此代码放在DidSelectRowAtIndexPath

NSArray* toReload = [NSArray arrayWithObjects: indexPath, self.selectedIndexPath, nil];
    self.selectedIndexPath = indexPath;
    if ([[tableView cellForRowAtIndexPath:indexPath] accessoryType] == UITableViewCellAccessoryCheckmark){

        BOOL selected = [[appDelegate.notesArray objectAtIndex:[indexPath row]] boolValue];
        [appDelegate.notesArray replaceObjectAtIndex:[indexPath row] withObject:[NSNumber numberWithBool:!selected]];

        [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
    }

    else {

        [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];

    }

我需要的是当用户从uitableview单元格中选择多个值时,它必须存储在一个数组中并将数组传递给按钮click.i希望这些数组在googledoc中共享。如何获取该数组来自UITbleViewCell.what代码的多个值我把它放在按钮点击?我想传递该值为share.if任何示例代码在那里供参考它对我来说将是一个很大的帮助。 提前致谢。 编辑:

- (IBAction)doUpload:(id)sender
{

    NSMutableArray *selected_items = [[NSMutableArray alloc] init];

    for (int i = 0; i<[appDelegate.notesArray count]; i++) {
        if (selected[i]) [selected_items addObject:[appDelegate.notesArray objectAtIndex:i]];


            UploadView *uploadview = (UploadView *)self.view;
            if (uploadview != nil)
            {

                [m_owner uploadString:@""];
                //[self dismissModalViewControllerAnimated:YES];
            }


        }    
}

2 个答案:

答案 0 :(得分:1)

我认为您的问题是如何进行多选表视图? - 如果是这样,这应该有所帮助:

在你的.h

BOOL selected[/* max number of cells */];

当用户选择单元格时

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        selected[row] = NO;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        selected[row] = YES;
    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

点击按钮

- (void)buttonClick {
    // pass the boolean array into the next controller, or just pass the items you need.
    // for example:


    for (int i = 0; i<[items count]; i++) {
        if (selected[i]) [m_owner uploadString:[items objectAtIndex:i]];
    }
}

请参阅here,了解我在多项选择中所做的演示项目。

答案 1 :(得分:0)

你桌子的大小是多少。如果不是很大,您可以使用int检查是否选择了行整数的每个位都代表表视图行的状态(是否选中)