私は 2 つの tableViews を持っています。1 つ目はメイン テーブルで、2 つ目はお気に入りテーブルです。
すべてがplistで処理されます。
最初のテーブルの detailView から、右上隅に、そのセルの値 YES または NO を plist に書き込むボタンを作成して、その特定のセルがテーブルのお気に入りに表示されるようにします。
問題は次のとおりです。
- メインのテーブルである最初のテーブルから行を選択します。detailView が表示され、その詳細をお気に入りにする UIBarButton をタップします (そのため、星の画像が画像としてボタンに表示され、セルがお気に入りであることをユーザーに知らせます)。わかった。
- 2番目のテーブルであるお気に入りのテーブルに移動し、以前にお気に入りにしたセルを選択すると、星が空であることがわかり、ブール値がNOに設定されます(そして、少し前にお気に入りにしたため、YESに設定されるはずです)。
firstTableの最初の項目をお気に入りに追加すると、最初のビューですべてお気に入りに追加した後でも、2 番目のビューの他のセルが正しく表示されることに気付きました。
少しトリッキーですが、それは起こっています。
理由はありますか?
plistを読み取るために使用している方法は次のとおりです。
- (NSArray*)readPlist
{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"tipsList.plist"];
NSFileManager *fMgr = [NSFileManager defaultManager];
if (![fMgr fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"list" ofType:@"plist"];
}
NSMutableArray *returnArr = [NSMutableArray arrayWithContentsOfFile:plistPath];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"];
for (NSDictionary *sect in returnArr) {
NSArray *arr = [sect objectForKey:@"Rows"];
[sect setValue:[arr filteredArrayUsingPredicate:predicate] forKey:@"Rows"];
}
return returnArr;
[self.tableView reloadData];
}
cellForRow:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView) {
rows = filteredList;
} else {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isFav == YES"];
NSDictionary *section = [localSortedTips objectAtIndex:indexPath.section];
rows = [section objectForKey:@"Rows"];
[rows filteredArrayUsingPredicate:predicate];
}
cell.textLabel.text = [[rows objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
そして、didSelectRow:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ NSDictionary *section = [localList objectAtIndex:indexPath.section];
NSArray *rows = [section objectForKey:@"Rows"];
NSDictionary *item = [rows objectAtIndex:indexPath.row];
detailViewController *detail = [[detailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
detail.indexPath = indexPath;
detail.imageString = [item valueForKey:@"image"];
detail.nameString = [item valueForKey:@"name"];
detail.title = [item valueForKey:@"name"];
detail.descriptionString = [item valueForKey:@"description"];
[self.navigationController pushViewController:detail animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[detail release];
}
}
写真で編集
そして。mainTable の最初のセクションの最初の行を選択すると、detailView が表示されます。
それから私はその小さな星を通してそれをお気に入りに入れ、その値をplistでYESに設定します
次に、お気に入りテーブルに移動し、以前にお気に入りにした要素をクリックすると、次のように表示されます
わかった。これは機能します。しかし、これだけです!
実際、mainTable の真ん中にある行を選択しようとして、それをお気に入りにしようとすると、detailView は次のようになります。
しかし、お気に入りテーブルでそれを選択すると、空の星のように見えますが、お気に入りに追加してから埋める必要があります。スターを使用してお気に入りに追加しようとして、お気に入りテーブルに戻ると、お気に入りに追加されていなくても、mainTable の前の行が表示されます。
最初の要素を保持すると正常に機能することに気付きましたが、削除すると何も機能しなくなります。:\
どんな助けでも大歓迎です、2週間から立ち往生しています。