「お気に入り|すべて」のオプションを持つセグメント化されたコントロールを作成し、それが切り替えられると、BOOL呼び出されるfavoritesOnlyか、またはその逆に切り替えYESられます。NO私の曲はNSArrayofNSDictionaryと呼ばれる sに保持され、これをメソッドsongsArrayとして使用します。DataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(favoritesOnly)
{
NSInteger count = 0;
for(int n=0; n<[songsArray count]; n++)
if([[[songsArray objectAtIndex:n] objectForKey:@"Favorite"] isEqualToString:@"YES"])
count++;
return count;
}
else
{
return [songsArray count];
}
}
次に、セルの場合:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *theCell = [tableView dequeueReusableCellWithIdentifier:@"Proto Cell"];
if(favoritesOnly)
{
NSInteger count = -1;
for(int n=0; n<[songsArray count]; n++)
{
if([[[songsArray objectAtIndex:n] objectForKey:@"Favorite"] isEqualToString:@"YES"])
{
count++;
if(count==[indexPath row])
{
//Configure the Cell using [songsArray objectAtIndex:n]
return theCell;
}
}
}
//If you got here there was an error; Error cell?
return theCell;
}
else
{
//Configure cell using [songsArray objectAtIndex:[indexPath row]]
return theCell;
}
}
このように、同じデータセットと同じUITableViewを使用しています。コントロールを使用してDataSource、情報を表示する方法を適切に委任しています。UITableView
ここで、CoreData と および を使用している場合NSFetchedResultsController、これはすべてはるかに簡単です。