0

哈,我正在做一个应用程序,它有一个共享笔记选项到印象笔记我成功地完成了它,我有一个包含文本的表格视图和一个用于将这些文本上传到印象笔记的按钮,如果用户单击单元格,则附加复选标记来了,他可以通过使用对uploade的复选标记来选择经文。但我的问题是当用户单击一个单元格并点击上传按钮时,它将上传行中的所有值,不仅是选定的行,而且是整行。我的代码是Buttonclick:

-(IBAction)sendNoteEvernote:(id)sender{

 NSMutableString *str = [[NSMutableString alloc] initWithString:@"NOTES:"];
    for (int i = 0; i<[appDelegate.notesArray count]; i++) {
        // UPLOAD STRINGS HERE
        if (selected[i])
        [str appendFormat:@"%@ ,",[appDelegate.notesArray objectAtIndex:i]];

        NSString * ENML= [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>%@",str];
}

str 是在 selectrowatindexpath 中上传代码的值:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

 NSUInteger row = [indexPath row];
    selected[row] = !selected[row];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = selected[row] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

in.hiBOOLEAN selected; 在vi​​ewdidload 中声明

for ( int i=0; i<[appDelegate.notesArray count]; i++) { 
    selected[i] = YES;
}
4

1 回答 1

0

我建议使用两条线索进行调试。首先,您选择的默认值是 YES,因此它假定默认情况下所有行都被选中。其次,由于您正在查看点击事件,因此切换代码:

selected[row] = !selected[row];

还不够,您需要遍历数组,将所有内容设置为 NO,除了您设置为 YES 的 indexPath.row。

for ( int i=0; i<[appDelegate.notesArray count]; i++) {
    if (i == indexPath.row) selected[i] = YES; else selected[i] = NO;
}
于 2012-01-17T15:15:40.970 回答