2014-03-02 2 views
0

두 개의 UITableViews, 하나의 사용자 정의 셀 XIB 테이블 뷰 및 다른 기본 동적 테이블 뷰가있는 UIViewController가 있습니다. 사용자 정의 셀 tableview는 대리자를 실행하지만 다른 테이블 뷰는 실행되지 않습니다. 코드하나의 UIViewController에서 사용자 정의 셀 테이블 뷰 및 기본 UITableView

@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]는 절대 위임을 호출하지 않습니다. 내가 어디로 잘못 가고 있니? , self

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

self보기 categoryTable를 포함하면 코드에서 UIViewController에 있습니다 :

+0

categoryTables 위임을 설정하셨습니까? – vikingosegundo

+0

예 - (IBAction)을 확인하십시오. catBtnPressed – KhanXc

+0

은'catBtnPressed :'wired up입니까? – vikingosegundo

답변

0

UITableView의 dataSource 및 delegate를 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 속성은 예를 들어, 컨트롤러를 참조하십시오 Question 컨트롤러.

+0

- (IBAction) catBtnPressed 메소드를 확인하십시오. 선언했습니다. – KhanXc

1

코드에서 categoryTable을 설정하기 전에 categoryTable.delegate을 설정하고 있습니다. 의미가 무엇인지 파악하기는 어렵지만 이것이 옳은 것처럼 보입니다. 코드에서 일부 발췌 촬영

, 그것은 당신이 위임 설정 곳, 여기에 설정하도록되어 무엇 categoryTable 분명하지 않다 : 몇 줄의 나중에 새 개체에 categoryTable을 설정 한 후

categoryTable.delegate = self; 

및 뷰에 추가 :

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

그래서 jQuery과의 예를 들어 당신이 reloadData가 호출되는 시점에서 대리자를 설정하지 않았습니다.

관련 문제