2011-12-11 16 views
0

哈II每一個身體,我用從一個UITableView單元選擇多個值附屬視圖對號,我把這個代碼在didSelectRowAtIndexPath方法如何使用附件視圖複選標記從UITableview單元格獲取多個值?

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獲取多個值的數組。我把它放在按鈕單擊中的哪個代碼?以及我想傳遞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]; 
      } 


     }  
} 
+0

可能的重複[如何從中獲取值只有桌面視圖checkmark是配件視圖?](http://stackoverflow.com/questions/8463013/how-to-get-values-from-a-tableview-only-checkmark-is-the-accessory-view) – jrturton

回答

2

我想你問的是如何做一個多選表視圖是什麼? - 如果是這樣,這應該幫助:

在您的.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爲我已經在多個選擇上做了一個示範項目。

+0

thnks的reply.this是我的代碼在按鈕中點擊UploadView * uploadview =(UploadView *)self.view; 如果(uploadview =零!) { [m_owner uploadString:路徑]; // [self dismissModalViewControllerAnimated:YES]; } }我想upld選定索引以gdoc,即。嘗試將路徑 – ICoder

+0

什麼是項目?我的數組? – ICoder

+0

我想傳遞字符串值繼續這個selced索引數組,[m_owner uploadString:在這裏我想傳遞值]; – ICoder

0

桌子的大小是多少?如果不大,您可以使用int來檢查是否選擇了一行或者整數的每一位將代表表格視圖行的狀態(選擇或不選)

相關問題