Search code examples
objective-cuitableviewios7

Unable to see TabelViewCell items of a dynamic TableView kept inside a View Controller


I'm working with Xcode 5 and I need to develop IOS app for iPad. I'm using a tableView inside a view controller. I'm populating the customized cell in the table view dynamically. I used a set of code and it worked for another table view situated in Table View Controller.but when I used the same code and procedure for the table view in the View Controller it shows blank cells.

Here is the code for cellForRowAtIndexPath in viewController.m where APMBasicSurveyItemTableViewCell is the class containing the UIControls situated in the cell.

APMBasicSurveyItemTableViewCell *cell = [_tblViewSurveyItem dequeueReusableCellWithIdentifier:APMSurveyItemBasicCellIdentifier forIndexPath:indexPath];
// Configure the cell...
APMQuestion *Question =[self.QuestionsData objectAtIndex:indexPath.row];
cell.lblQuestionDetail.text=Question.Detail;
return cell;

Here is what I have written in viewController.h

@interface APMSurveyItemViewControll :UIVIewController <UITableViewDelegate,UITableViewDataSource>;
@end

Solution

  • It appears that you didn't set the data source for your table view. To confirm this add a break point to each of the data source delegate methods and run your application. (comments in the Add Break Points code block below, indicate lines you should add the breakpoints to)

    If the data source has not been set for the tableview, your application will not hit any of the break points you've just added. Then follow one the the following approaches to set the delegate for your table view.

    1. If you are using the story board you can visually set the outlet: enter image description here
    2. Other wise you can set the delegate manually: Create an outlet from your table view to your view controller and set the tableview's delegate to self.

    Setting datasource

    - (void)viewDidLoad
    {   
        self.tableView.dataSource = self;
    }
    

    Then run your application again with the break points listed above and you should hit the data source delegate method break points.

    Adding Breakpoints

    #pragma mark - Table View Data Source
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1; //Add a breakPoint to this line
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.tempEventData.count;  //Add a breakPoint to this line
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath
    {
        static NSString *CellIdentifier = @"Cell"; //Add a breakPoint to this line
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:CellIdentifier];
        }
        cell.textLabel.text = [self.tempEventData objectAtIndex:indexPath.row];
        return cell;
    }