2014-10-29 42 views
0

我想用兩個tableviews像... ..如何使用按鈕

使用兩個tableviews我使用酥料餅控制器

第一的tableview是在那個酥料餅控制器酥料餅控制器 我有兩個按鈕(添加註釋按鈕,其餘的按鈕) 當我在其餘按鈕點擊我躲在我的第一tableview中並啓用第二的tableview

UT第二個實現代碼如下的cellForRowAtIndexPath不調用

僅對第一的tableview它呼籲,不要求第二表視圖

這裏我的代碼是......... ..

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


    if (tableView==self.remainderTableView)//second Tbleview { 

     static NSString *[email protected]"Celliden"; 
     UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
     if (cell==nil) { 
      cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 

     [email protected]"hhh"; 
     return cell; 

    } 
    else if (tableView==self.NotesandRemainderTable)//first Tableview { 

     static NSString *cellIdentifier = @"bookingCell"; 

    CustomTableViewSwipeCell *cell = (CustomTableViewSwipeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 

     NSString *note=[jsondata valueForKey:@"TeacherNotes"]; 

     NSLog(@"teacher notes %@",note); 
     // if (cell==nil) { 
     //  cell=[[CustomTableViewSwipeCell alloc]init]; 
     // } 
     // Add utility buttons 

     NSMutableArray *rightUtilityButtons = [NSMutableArray new]; 


     [rightUtilityButtons sw_addUtilityButtonWithColor: 
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] 
                title:@"Delete"]; 

     _SubjectLabel.text=AppDel.sub; 
     NSLog(@"the date %@",AppDel.date); 
     _DateLabel.text=_dateToDisplay; 
     if (indexPath.section==0) 
     { 
      if (indexPath.row==0) 
      { 
       cell.Noteslabel.text=note; 



      } 


      return cell; 

     } 
     if (indexPath.section==1){ 

      cell.Noteslabel.text=[_notesArray objectAtIndex:indexPath.row]; 

      //NSLog(@"notes index %@",[notesArray objectAtIndex:indexPath.row]); 
      cell.rightUtilityButtons = rightUtilityButtons; 
      cell.delegate=self; 
      return cell; 


     } 
    } 
      //cell.rightUtilityButtons = rightUtilityButtons; 
    return nil; 

} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView==self.NotesandRemainderTable) { 
     if (section==0) { 
      return 1; 
     } 

     else if (section==1) { 

      if (leanerNots==nil || [leanerNots isEqual:[NSNull null]]) { 
       return 0; 
      } 
      else{ 

       return [_notesArray count]; 
      } 

     } 

    }else{ 
     return 3; 
    } 
     return 0; 
} 

//這是我的其餘按鈕的代碼..... 。

-(IBAction)addRemainderAction:(id)sender{ 
    self.lineLabel.hidden=NO; 
    self.remainderTableView.hidden=NO; 
    self.addButtonObj.hidden=NO; 
    //self.remainderTableView.frame=CGRectMake(0, 62, 300, 321); 

    //[self.view addSubview:self.remainderTableView]; 
    self.NotesandRemainderTable.hidden=YES; 
    self.notesBtnObj.hidden=YES; 
    self.remainderBtnObj.hidden=YES; 
    _SubjectLabel.hidden=YES; 

} 

任何一個可以幫助解決這個bug ......我是新Xcode的

回答

0

你設置你的第二個的tableview的數據源和委託?

在viewDidLoad中

例如:

self.remainderTableView.datasource = self; 
self.remainderTableView.delegate = self; 

而且有可能需要在顯示前重新加載tableviews。要做到這一點使用下面的代碼爲你的第二個實現代碼如下

[self.remainderTableView reloadData]; 
+0

雅我補充說..儘管它不工作..... – iworld 2014-10-29 13:55:11

+0

你也加了reloadData方法嗎?在addRemainderAction中 – dfinki 2014-10-29 14:18:44

0

這不是從這個代碼完全清楚是否已正確設置delegatedataSource兩個UITableView實例。如果你沒有,那麼這些委託方法將永遠不會被調用。

無論如何,通過使用兩個數據集而不是兩個tableViews可以更好地處理這種情況。按照與現在相同的方式實施cellForRowAtIndexPath,除了基於tableView的值有條件地創建您的單元格,只需使用您的UIButton的值即可。當UITableViewDelegateUITableViewDataSource方法允許您很容易地從不同的數據集中採集數據時,兩個UITableViews對於這種情況似乎有點過大。