2017-04-10 74 views
0

在UIView類添加UIViewController具有UITableView類現在UIView類被添加到另一個UIViewController類的cellForRowAtIndexPath方法沒有調用

//MyControllerView 
//added filterSideView side to it and adding JaffaViewController.view 
-(void)loadControllerJaffa 
{ 
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" 
                 bundle:nil]; 
    JaffaViewController *jaffaViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"JaffaViewController"]; 
    jaffaViewController.view.frame = filterSideView.bounds; 
    [filterSideView addSubview:jaffaViewController.view]; 
    [jaffaViewController didMoveToParentViewController:self]; 
} 


#import <UIKit/UIKit.h> 

@interface JaffaViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> 
@property (weak, nonatomic) IBOutlet UITableView *jaffaTableView; 

@end 

實現類

@implementation JaffaViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _colorNameList = [[ColorModelClass colorListNames]allKeys]; 
    _jaffaTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 
    _jaffaTableView.dataSource = self; 
    _jaffaTableView.delegate = self; 
    [_jaffaTableView setBackgroundColor:[UIColor redColor]]; 


     // Do any additional setup after loading the view. 
} 

-(void)viewDidAppear:(BOOL)animated{ 
    [super viewDidAppear:YES]; 
    _jaffaTableView.dataSource = self; 
    _jaffaTableView.delegate = self; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; //count of section 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5; 
} 


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


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableCell"]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:@"SimpleTableCell"]; 

    } 
    cell.textLabel.text = @"Welcome"; 
    return cell; 


} 

問題是cellForRowAtIndexPath方法不調用在所有。 我已經設置了數據源和委託方法。

它調用numberOfRowsInSectionnumberOfSectionsInTableView兩種方法,但不是cellForRowAtIndexPath方法。 當前我正在使用Xcode 8.3 & iOS 10.3版本。 您的善意輸入將幫助我解決問題。

+0

如果numberOfRows或Sections爲零。它不會被撤銷。檢查numberOfRows –

+0

確保委託方法設置正確。這是最重要的。我知道你已經完成了所有這些事情。但我要求你確定一下。 –

+0

@SivajeeBattina我會檢查數據源和委託方法。 – kiran

回答

0

請試試這個代碼

-(void)loadControllerView { 
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" 
                bundle:nil]; 
    JaffaViewController *jaffaViewController = 
    [storyboard instantiateViewControllerWithIdentifier:@"JaffaViewController"]; 

    [jaffaViewController willMoveToParentViewController:self]; 
    jaffaViewController.view.frame = filterSideView.bounds; 
    [filterSideView addSubview:jaffaViewController.view]; 
    [jaffaViewController didMoveToParentViewController:self]; 
} 

注:

請確保您有確認的數據源,並委託它。

+0

我試過沒有工作。 – kiran

0

爲什麼設置數據源兩次?刪除viewDidAppear中的代碼,並在viewDidLoad末尾添加[_jaffaTableView reloadData];

0
tingViewController *destVC = [self.storyboard instantiateViewControllerWithIdentifier:@"RatingViewController_id"]; 


destVC.completionHandler = ^(NSString* string) 
{ 
    NSLog(@"Returned strng.....%@",string); 
}; 

destVC.productId = self.productId; 

[destVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
[self addChildViewController:destVC]; 
[self.view addSubview:destVC.view]; 
[destVC didMoveToParentViewController:self]; 

[UIView animateWithDuration:0.3 animations:^{ 
    [destVC.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
}]; 
相關問題