2012-01-13 19 views
2

私の目的は、view1のボタンをクリックしたときに、UITableViewから選択したすべてのセルをにチェックインしました。 テーブルを次のビューに渡す前に、正しいトラックにいるかどうかをテストしたいと思いますが、そうではないようです。これは私のコードです:選択したすべてのセルの値を取得する

-(IBAction)goToView2{ 
    //get all section selectioned items into an array 
    themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file 
    for (int i=0; i<=[themesChosed count]; i++) { 
     NSLog(@"%i",[[themesChosed objectAtIndex:i]integerValue]); 
    } 


} 

私はテーブルの上にいくつかの項目を選択したが、これはいつも私に単一0

2012-01-13 15:52:06.472 MyApp[876:11603] 0 

を返します。

+0

のNSLogを(何@ "%d"、themesChosed.count);ショー?これは、テーブルビューの選択項目の数と同じですか? –

答えて

5

themesChosedのオブジェクトはNSIndexPathオブジェクトです。あなたはそのようなrowsectionプロパティにアクセスすることをお勧めします:

-(IBAction)goToView2{ 
    //get all section selectioned items into an array 
    themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file 
    for (int i=0; i<=[themesChosed count]; i++) { 
     NSIndexPath *thisPath = [themesChosed objectAtIndex:i]; 
     NSLog(@"row = %i, section = %i", thisPath.row, thisPath.section); 
    } 
} 
+0

こんにちは、あなたの答えはありがとう、実際には、私が選択したセクションと何行を選択しても、私は常に0を取得し続ける: '行= 0、セクション= 0 ' – Malloc

+0

あなたが思っているように、アウトレットが接続されていない、または2)行が選択されていない。 – agilityvision

2

最初はNSIndexPathは整数ではありませんが、行とセクションのメソッドを持つオブジェクトなので、おそらくゼロになるのです。 allowsMultipleSelectionをYESに設定してもよろしいですか?

0

あなたはインデックス値を取得されていません場合は、最善のアプローチ傷がインデックス番号にアクセスするには、以下のようになる:

NSArray *indexes = [self.tableView indexPathsForSelectedRows]; 
    for (NSIndexPath *path in indexes) { 
    NSUInteger index = [path indexAtPosition:[path length] - 1]; 
    [selectedOptionsArray addObject:[optionHolderArray objectAtIndex:index]]; 
    }