2016-04-05 12 views
0

Help me!私はセクションtableviewsにセルを挿入することができません!テーブルビューのセルとセクションを挿入する

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
      NSInteger result = 0; 
      result = [[_dictionoryOfDay allKeys] count]; 
      return result; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
     NSInteger result = 0; 
     NSString *sectionNameInDictionary = [[_dictionoryOfDay allKeys] 
             objectAtIndex:section]; 
     NSArray *sectionArray = [_dictionoryOfDay objectForKey: 
          sectionNameInDictionary]; 
     result = [sectionArray count]; 
     return result; 
    } 

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

     UICustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellMain" forIndexPath:indexPath]; 
     [cell.btnAddMore addTarget:self action:@selector(actionAddMore:)forControlEvents:UIControlEventTouchUpInside]; 
     cell.btnAddMore.tag = indexPath.section; 
     return cell; 
    } 

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 
     TableHeaderAvailabel *header; 
     if(!header){ 
       header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"TableHeaderAvailabel"]; 
     } 
     NSString *result = nil; 
     result = [[self.dictionoryOfDay allKeys] objectAtIndex:section]; 
     header.lbTitle.text = result; 
     return header; 
    } 

    -(void)actionAddMore:(UIButton *)sender{ 

    } 
+0

のようになります。あなたのコードを少しは良く理解できるように、あなたの質問を再フォーマットできますか? 「ヘルプ」テキストを使用して、コードを適切なMarkdownフォーマットで囲む方法を示します。また、問題を解決しようとしたことを示してください。 – fsb

+0

あなたの問題は何ですか? 'actionAddMore'が空の行/セクションを挿入しているコードはどこですか? – HardikDG

+0

image:http://i.stack.imgur.com/lJNTE.jpg –

答えて

1

私の推測では、あなたがセルのbtnAddMoreにタップすると、あなたのセクションにを追加したいということです。その場合はactionAddMore()の実装は

NSString *sectionNameInDictionary = [[_dictionoryOfDay allKeys] 
            objectAtIndex:section]; 
    NSArray *sectionArray = [_dictionoryOfDay objectForKey: 
         sectionNameInDictionary]; 
    // Create whatever you use to populate rows 
    [sectionArray addObject: <your new object>]; 
    _dictionaryOfDay[sectionNameInDictionary] = sectionArray; 
    [self.tableView reloadData]; // Or just load the new cell, but this is easier 
+0

これは私の画像です http://postimg.org/image/ecmjk21or/ –

+0

ありがとうございました! 例:火曜日または木曜日のセクションにセルを挿入します。今はできますか? これは私の画像です http://postimg.org/image/ecmjk21or/ –

+0

ありがとうございました! –

関連する問題