2

このサイトのいくつかの投稿を精査しましたが、正確な問題が見つからなかったので、アドバイスを探しています. 私は現在、現在の TableView をサポートするために使用する TaskList エンティティを持つアプリを持っています。エンティティの複数の属性に基づいてセクションを作成したいと考えています。たとえば、「isShared 」属性とbool「完了」bool属性があり、「共有」アイテム、「非共有」アイテム、および「完了」アイテムをグループ化するセクションを表示したいと考えています。

これは一時的なプロパティが機能する状況ですか? 私が見たほとんどのアプリケーションは単一の属性にしか適用されないため、それについて頭を悩ませることはできませんでした。

前もって感謝します。

4

2 に答える 2

0

私は頭の中で考えを持っていますが、これは最善の解決策ではないかもしれません。bool属性に基づいて、「isShared」、「notShared」、および「completed」のオブジェクトを含む3つの配列を作成できますか?

次に、テーブルビューセルメソッドで

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //Custom your cell for different section here
    switch (indexPath.section)
    {
         //First section is shared item
         case 0:
              if(cell == nil){
                  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
             //Custom your cell here, for example, you can assign an item in your list to the cell's textlable
             cell.textLabel.text = [sharedArray objectAtIndex:[indexPath row]];
             }
             break;
         case 1:
              if(cell == nil){
                   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
              //Custom your cell for not shared item here
              cell.textLabel.text = [notSharedArray objectAtIndex:[indexPath row]];
              }
              break;
          case 2:
              if(cell == nil){
                   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
              //Custom your cell for not shared item here
              cell.textLabel.text = [CompletedArray objectAtIndex:[indexPath row]];
              }
               break;
          default:
               break;
    }
    return cell;
}

したがって、bool属性でグループ化された3つのセクションがテーブルビューに表示されます。リスト内の1つのアイテムを変更する場合、つまり、非共有セクションから1つの非共有アイテムを共有する場合は、そのオブジェクトをunSharedArrayからsharedArrayに移動するメソッドを実装してから、を呼び出す必要があります。

[tableView reloadData]

テーブルビューを更新します。

于 2011-07-08T18:22:44.297 に答える
0

配列付きの辞書を使用します。TableViewControllerのinitまたはviewDidLoadメソッドに辞書を入力します。

于 2011-07-08T18:30:00.023 に答える