2

辞書の配列を含むplistを使用して、MutableArrayを介してMainTableViewControllerを埋めます。セルが選択されると、再表示されたディクショナリがDetailViewControllerに渡され、そこで再表示されたディクショナリの文字列の値が表示されます。ストーリーボードのDetailViewにボタンを追加しました。このボタンで、表示された辞書を[お気に入り]タブ(FavoritesTableViewController)に送信します。私はそれを行う方法を考えていますが、プログラミングは初めてなので、アドバイスを求める必要があります。

私はそれを行うための2つの可能な方法を考え出しました。私は正しい答えから遠く離れているかもしれませんが、少なくとも私は考えようとしています。

1:ボタンは、表現された辞書でブール値をyesに変更し、FavoritesViewControllerのプロトタイプセルは、boolean=yesで辞書を表示するように指示されます。

2:ボタンは、お気に入りのテーブルビューに表示されるお気に入りの新しいplistに辞書をコピーします。

しかし、私は本当にわかりません。

編集:

これまでのDetailViewControllerのコード:

-(IBAction)FavoriteButton:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ItemSelected"
                                                    object:selectedObject];


}

これまでのコードで、FavoritesViewControllerにワインを表示します。

[[NSNotificationCenter defaultCenter] addObserverForName:@"ItemSelected"
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification* notif) {
                                                  [favoritedObjects release];
                                                  favoritedObjects = [[notif object] retain];
                                                  [self.tableView reloadData];
                                              }];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [favoritedObjects count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Favcell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

    NSString *cellValue = [favoritedObjects valueForKey:@"Name"];
    cell.textlabel.text = cellValue;

    return cell;
}

これは、キーの値を持つ20個のセルを示しています:「お気に入りに追加」ボタンを押したDetailViewControllerの最後のオブジェクトの「名前」。たとえば、お気に入りに「Gato Negro」を追加すると、20個のセルに「GatoNegro」が表示されます。次に「Luna」をfavに追加すると、FavoritesViewControllerの20個のセルに「Luna」が表示されます。

4

1 に答える 1

0

通知を投稿して、選択した辞書をまたはとして渡すのはobjectどうですかuserInfo

[[NSNotificationCenter defaultCenter] postNotificationName:@"ItemSelected"
                                                    object:mySelectedDictionary];

FavoritesViewControllerあなたはこの通知を次のように(例えばメソッドで)購読するだけですinit

[[NSNotificationCenter defaultCenter] addObserverForName:@"ItemSelected"
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification* notif) {
                                                  [dictionaryToShow release];
                                                  dictionaryToShow = [[notif object] retain];
                                                  [self.tableView reloadData];
                                              }];
于 2012-07-13T13:30:33.823 に答える