2012-01-17 95 views
0

哈II,是做具有共享注意選擇到Evernote我做它成功地一個應用程序,我有一個包含文本和上傳這些文本到Evernote一個按鈕的tableview,如果用戶單擊單元格的accsocory複選標記來了,他可以通過使用複選標記uploade.but我的問題是,當用戶點擊一個單元格,然後點擊上傳按鈕,將上傳行中的所有值不僅sectled行,但也是整個選擇的詩句行。 我的代碼是 Buttonclick:的UITableView didselectRowAtIndex懷疑

-(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.hi declate BOOLEAN selected; 在viewDidLoad中

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

回答

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; 
}