2014-03-02 102 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被調用。

相關問題