Question

Ha ii ,am doing a application which has a share Note option to evernote i done it sucessfully,i have a tableview which contains text and a button for upload these text to evernote,if the user click the cell the accsocory checkmark is come and he can select the verse by using checkmark for uploade.but my problem is when the user click the one cell and tap the upload button it will upload all the values in the row not only the sectled row but also the entire row. My code is 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 is the value that is uploaded code in 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.h i declate BOOLEAN selected; in viewdidload

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

Solution

I would suggest two leads for debugging. First your default values of selected are YES, so it assumes all rows are by default selected. Second, since you're looking at the tapping event, the toggle code :

selected[row] = !selected[row];

is not enough, you need to loop through the array, set everything to NO, except the indexPath.row that you set to YES.

for ( int i=0; i<[appDelegate.notesArray count]; i++) {
    if (i == indexPath.row) selected[i] = YES; else selected[i] = NO;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top