2012-02-15 14 views
9

1つの動的セクションで静的なテーブルビューを定義したい これは可能ですか?「静的セル」を含む静的なTableviewに「ダイナミックプロトタイプ」を含むセクションを含める

セクション0は静的で、lcodeはアウトレットとxcodeで配線されています。

部1は、動的

ものでなければならない私はこれを試してみましたが、私は、静的な部分のために返還しなければ何のセルを知っているドント。

static NSString *CellIdentifier = @"ItemCellBasic"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

switch (indexPath.section) 
{ case 0: 
    return // I don´t know what 

    case 1: 
    cell.textLabel [email protected]"dynamic"; 
    return cell;  
} 

EDIT 1;

case 0: return [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

をしかし得た: は今、私が試した

*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 
+0

プロパティ:xcodeの "content"は "静的セル"または "ダイナミックプロトタイプ"です。 – mica

答えて

5

私はスーパークラスの静的セルに結果を返すテーブルビューのデータソースの方法では、この問題

のための部分的な解決策を持っています動的セルの場合、必要な動的値を返します。 dequeueReusableCellWithIdentifier indexPath(NSIndexPath *)::(のUITableView *)のtableView cellForRowAtIndexPath:戻りので、私は新しいのUITableViewCell

残りの問題を作成してnilを:

Xcodeであなたは(のUITableViewCell *)のtableView - で

"動的セクション"の行の数を指定しなければなりません(動的ではありません)。ここで定義した最大値以上を表示することはできません(または例外;-)を得ることができます)。

のSampleCode:代わりに、スイッチの

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    switch (section) 
    { case STATIC_SECTION: 
     return [super tableView:tableView numberOfRowsInSection:section]; 

    case DYNAMIC_SECTION 
     return NUMBER_OF_DYNAMIC_ROWS; 
    } 
} 

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

    switch (indexPath.section) 
    { 
    case STATIC_SECTION: 
     return [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

    case DYNAMIC_SECTION: 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (!cell) 
     { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; 
     } 

     cell.textLabel.text=DYNAMIC_TEXT; 
     return cell;  
    } 

} 
+0

実際には、任意の数のダイナミックセルを追加できます。 [リンク](http://stackoverflow.com/questions/10043521/adding-unknown-number-of-rows-to-static-cells-uitableview/10060997#comment15940351_10060997)を参照してください。 – DanSkeel

-1

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
     if(section==STATIC_SECTION){ 
      return *the number of rows in the static section* 
     } 
     else{ 
      return NUMBER_OF_DYNAMIC_ROWS; 
     } 
    } 

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

    static NSString *CellIdentifier = @"ItemCellBasic"; 
    UITableViewCell *yourCell = [tableView dequeReusableCellWithIdentifier:CellIdentifier forIndexpath:indexPath]; 

    yourCell.text = *your dynamic text or something* 

    return yourCell; 
} 

が今、あなたの静的な細胞が再利用識別子を持っていないと仮定した場合、いくつかの古き良きを使用してみてください、ただ冗長になる原因、再利用のために1つのプロトタイプセルしか必要としないので、これはあなたの設定でなければなりません。

関連する問題