2010-12-21 7 views
0

私はそのアプリで1つのアプリケーションを書いています。私は2つのcells.whileで最初のセルtableviewを表示する必要がありますビュー内で(私はここでナビゲーションを使用することはできません)また、2番目のセルも表示されます。いずれか1つ私にこれのための提案を教えてください。 ありがとうございます。私たちは1つのセルをクリックする必要があるときはいつでもテーブルビューのセルを表示する方法

答えて

1

あなたはセルをクリックしたときのテーブルビューセルを挿入したい場合は、次のコードを試してみてください。

0のセクション1,2,3の3つの行を挿入するとします。didSelectRowAtIndexPathメソッドでは、次の操作を行います。セクション0(最初のセクション)で行0(最初の行)を選択すると、ここで行がセクション0に挿入されます。あなたのnumberOfRowsInSection方法で

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

    if (indexPath.row == 0 && indexPath.section == 0) { 

     // Create indexPaths for the rows you are going to insert 

     NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:1 inSection:0]]; 
     NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:2 inSection:0]]; 
     NSIndexPath *indexPath3 = [NSIndexPath indexPathForRow:3 inSection:0]]; 

     // Increase the number of rows in section 0 by 3, as we are inserting 3 rows here 

     numberOfRowsInSectionZero = numberOfRowsInSectionZero + 3; 

     // Insert the rows 

     [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, indexPath2, indexPath3, nil] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

、あなたは

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { 

    // some code here 

    if (section == 0) return numberOfRowsInSectionZero; 

    // some code here 
} 

そして、あなたはcellForRowAtIndexPathで新たに表示中のコンテンツを表示する方法を適切なコードを持っていることを確認して、次のようなものを持つべきです行。

注:すでに挿入されているセクション0の行0をクリックすると、行が挿入されないようにコードを変更する必要があります。

0

は、ブール値(isRowClick)変数とdidSelectRowで

設定YESを行い、その後、これがあなたのHEPます

[yourTable reloadData]; 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

if(isRowClick) 
    return 7;//according to you 
else 
    return 2; 
} 



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

    isRowSelect=YES; 
//stuff 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

//stuff according to you 
} 

この行を書きます。

0
  1. などのデータオブジェクトを定義します。 NSMutableDictionary
  2. ユーザーが定義されたセルをクリックした場合は、常にこのオブジェクト(表示する値および表示する値)のデータを読み出します。
  3. MutableDirectoryをフラッシュして新しいデータを追加します。
  4. リロードTableViewController [tableviewController.tableview reloadData];

のthatsそれ 歓声サイモン

関連する問題