2014-03-02 111 views
0

我有两个UITableViews,一个自定义单元格XIB的tableview和另一个默认动态tableview.The自定义单元格的tableview一个UIViewController触发其委托但其他表视图不会。这里是我的代码自定义单元格的tableview和默认的UITableView在一个UIViewController中

@interface Question : UIViewController<UITableViewDataSource,UITableViewDelegate> 

而且.M

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
if(tableView == _similarTable) 
    { 
tableCell =(SimilarQuestion *)[_similarTable dequeueReusableCellWithIdentifier:@"similarTable"]; 

if(tableCell == nil) 
    { 
tableCell = [[[NSBundle mainBundle]loadNibNamed:@"SimilarQuestion" owner:self options:Nil]objectAtIndex:0]; 

    } 
if(finalAskerArray!=nil && finalQuesArray.count >0) 
    { 
tableCell.questionText.text= [finalQuesArray objectAtIndex:indexPath.row]; 
tableCell.lblAsker.text=[finalAskerArray objectAtIndex:indexPath.row];   
    } 
    return tableCell; 
} 
else 
{ 
    NSLog(@"==>Hit"); 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"categoryTable"]; 
    if (cell == nil) 
    { 
     cell = [[[NSBundle mainBundle]loadNibNamed:@"categoryTable" owner:self options:nil]objectAtIndex:0];    
    } 
    if(popCategoryArray != nil && popCategoryArray.count >0) 
    { 
     cell.textLabel.text = [popCategoryArray objectAtIndex:indexPath.row]; 
    } 
    return cell; 
} 
} 

我呼吁点击按钮的默认表视图,就按一下按钮的代码如下

-(IBAction)catBtnPressed:(id)sender{if(categoryArray.count !=0) { 
popCategoryArray = categoryArray; 
    categoryView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320 , 548)]; 
    categoryTable.delegate = self; 
    categoryTable.dataSource =self ; 
      [UIView transitionWithView:categoryView duration:2.0 
         options:UIViewAnimationOptionTransitionFlipFromTop 
        animations:^{ 
         [self.view addSubview:categoryView]; 
        }  completion:NULL]; 

    categoryTable = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 240)]; 
     [categoryTable reloadData]; 
    [categoryView addSubview:categoryTable]; 
    [self.view addSubview:categoryView]; 

} 

}

[categoryTable reloadData]永远不会调用委托。我哪里错了?

+0

您是否设置了categoryTables委托? – vikingosegundo

+0

是检查 - (IBAction为)catBtnPressed – KhanXc

+0

是'catBtnPressed:'有线了? – vikingosegundo

回答

0

你应该设置数据源和委托的UITableView它的init方法。

-(IBAction)catBtnPressed:(id)sender{if(categoryArray.count !=0) { 
popCategoryArray = categoryArray; 
    categoryView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320 , 548)]; 
    [UIView transitionWithView:categoryView duration:2.0 
         options:UIViewAnimationOptionTransitionFlipFromTop 
        animations:^{ 
         [self.view addSubview:categoryView]; 
        }  completion:NULL]; 

    categoryTable = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 240)]; 
    categoryTable.delegate = self; //move from above 
    categoryTable.dataSource = self; //move from above 
    [categoryTable reloadData]; 
    [categoryView addSubview:categoryTable]; 
    [self.view addSubview:categoryView]; //You have addSubview:categoryView in above UIView animation, maybe should not add here 

} 
0

呼叫categoryTable.reload()之前,首先要确保您的categoryTabledelegate财产和dataSource财产是指你的控制器,例如:

categoryTable.delegate = self ; 
categoryTable.dataSource = self ; 

self是其视图包含categoryTable,在你的代码的UIViewController,selfQuestion控制器。

+0

检查 - (IBAction)catBtnPressed方法我已经声明了它 – KhanXc

1

在代码中,要设置categoryTable.delegate设置categoryTable之前。很难弄清楚是什么意思,但这看起来不正确。

以从你的代码的一些摘录,目前还不清楚应该什么categoryTable在这里设置,在这里设置委托:

categoryTable.delegate = self; 

那么几行后,你设置categoryTable到一个新的对象,它添加到视图:

categoryTable = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 240)]; 
    [categoryTable reloadData]; 
[categoryView addSubview:categoryTable]; 

所以UITableView中的该实例你没有设置委托在点reloadData被调用。

相关问题