1

私は現在、演習でいっぱいの.plistによって作成されたUITableViewを持っています。私ができるようにしたいのは、クリックされた各演習を配列に格納することによって、テーブル内の個々の演習にアクセスすることです。これは、後で個別のUITableViewにデータを入力するために使用されます。

これらの個々のセルにアクセスして、この配列に格納できるようにするには、どのようにすればよいですか。これが私がこれまでに持っているものです:

-(IBAction) saveWorkout {
    NSMutableArray *workout = [NSMutableArray arrayWithCapacity:10];

    [workout addObject: ] // I'm assuming this is where I add a cell to an array (or atleast the cell's string).

}

何か助けはありますか?

4

3 に答える 3

0

-(void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

ここでindexPath.rowによってインデックスを取得できます

}

于 2012-04-09T07:21:59.717 に答える
0

コードで @CodaFi を言い換えるには:

@property (strong, nonatomic) NSMutableArray *selectedElements;
@synthesize selectedElements=_selectedElements;

- (NSMutableArray *)selectedElements {
    if (!_selectedElements) {
        _selectedElements = [NSMutableArray array];
    }
    return _selectedElements;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    id element = [self.myModel objectAtIndex:indexPath.row];
    // this is the key:  this array will now be the basis for your subsequent table of selected items
    [self.selectedElements addObject:element];

    // do something to your model here that indicates it's been selected
    // have your cellForRow... method interrogate this key and draw something special
    [element setValue:[NSNumber numberWithInt:1] forKey:@"selected"];

    // reload that row so it will look different
    [tableView beginUpdates];
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
于 2012-04-09T04:10:20.680 に答える
0

質問の実際のコード部分を深く掘り下げることなく-cellForRowAtIndexPath、タイトルを取得するための呼び出しは、特に複数回呼び出される場合、非常に高価です (可能性があります)。を使用-didSelectRowAtIndexPath:してデータソース配列内のタイトルのインデックスを取得し、そのオブジェクトをリストに追加します。-saveWorkout終了/特定の制限に達したときに呼び出します。

同じように見えるかもしれません:

-(void)didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
     //other code and such... 
     //get the index of the object in our original array and add the corresponding object to the new array.
     [customWorkoutArray addObject:[workoutArray objectAtIndex:indexPath.row]];
}
于 2012-04-09T03:49:07.907 に答える