Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:04:52+00:00 2026-06-13T09:04:52+00:00

I have a problem in populating a uitableview created programmatically as a subview of

  • 0

I have a problem in populating a uitableview created programmatically as a subview of uicollectionview.

here’s my code:

.h file

#import <UIKit/UIKit.h>

@interface TheViewController : UICollectionViewController<UITableViewDataSource>
@property (atomic,strong) IBOutlet UIBarButtonItem *plus;
-(IBAction) addTeamPressed:(id)sender;
@end

.m file

- (void)viewDidLoad
{
    [super viewDidLoad];
   NSError *jsonParsingError = nil;

    teamsView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.window.bounds.size.width, self.view.window.bounds.size.height)];
    NSData *t = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://..."] options:NSDataReadingMappedIfSafe error:&jsonParsingError];

    NSArray *tmp = [NSJSONSerialization JSONObjectWithData:t options:0 error:&jsonParsingError];
    UITableViewCell * teamCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    teams = [[NSMutableArray alloc]init];
    [teamsView addSubview:teamCell];

teamsView.delegate = self;

teamsView.dataSource = self;
    for(int i =0;i<tmp.count;i++){
        [teams addObject:[tmp objectAtIndex:i]];
    }
    plus.title = @"Done";

    [self.view addSubview:teamsView];

}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    // If You have only one(1) section, return 1, otherwise you must handle sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [teams count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    TeamsNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[SquadreNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.name.text = [NSString stringWithFormat:@"%@",[[teams objectAtIndex:indexPath.row] objectForKey:@"name"]];
    NSLog(@"%d teams",[teams count]);
    return cell;
}

my tableview is displaying correctly, of course thanks to other functions not mentioned here, but no rows in the subview.
the compiler prints out the number of teams, so it calls the delegate methods, but it doesn’t populate the subview…

what ‘s wrong with this?

thanks in advance
Dario

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:04:53+00:00Added an answer on June 13, 2026 at 9:04 am

    First you should remove this from your viewDidLoad:

    UITableViewCell * teamCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    [teamsView addSubview:teamCell];
    

    Then make sure that your teams array is retained, just put this line to the header file:

    @property (nonatomic, strong) NSMutableArray* teams;
    

    And then use self.teams instead of just teams

    At the end of viewDidLoad method you should call [teamsView reloadData];

    Also it would be good to change your table data source method:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        TeamsNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (!cell) {
            // please make sure that you allocate required object here
            cell = [[TeamsNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        // please make sure that you do have `name` property in your `TeamsNameCell` class
        cell.name.text = [NSString stringWithFormat:@"%@",[[teams objectAtIndex:indexPath.row] objectForKey:@"name"]];
        NSLog(@"%d teams",[teams count]);
        return cell;
    

    }

    Please make sure that your TeamsNameCell class has name property in the header:

    @property(nonatomic, strong) UILabel* name;
    

    And also do not forget to allocate this label in the constructor of TeamsNameCell:

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            self.name = [[UILabel alloc] initWithFrame:CGRectMake(0,0,100,50)];
            [self addSubview:self.name];
        }
        return self;
    }
    

    Or Maybe it is better to use default cell’s label:

    instead of cell.name.text = @"text"; use cell.textLabel.text = @"text";

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie here! My problem is as follows: I have a dynamically populating ul where
I have created my application by populating spinners within my Java code. I am
I'm stuck with a problem populating an UITableView . I have got an NSMutableArray
I have a problem with populating an autocomplete list based on a previous input.
We have accounting software populating the name field on a magento webstore, the problem
I have a problem with formating text into TextView fields. I am populating strings
I have a bit of an odd problem. I have been populating a UITextView
I currently have this code for populating a list of comments to return: foreach
I have a UITableView I'm populating with data from CoreData. I have a data
So here is the problem i'm running into. Originally, I was populating the recipient

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.