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 6977731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:39:48+00:00 2026-05-27T17:39:48+00:00

I am trying to add 2 UITableView ‘s to my UIViewController . I need

  • 0

I am trying to add 2 UITableView‘s to my UIViewController. I need to add different data to these tables.

This is how i added the 2 tables (this code was added to the ViewDidLoad method)

self.tableView2 = [[UITableView alloc] initWithFrame:CGRectMake(0,140,292,250) style:UITableViewStylePlain] ;
self.tableView2 .dataSource = self;
self.tableView2 .delegate = self;

Then the other table

self.tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,100) style:UITableViewStylePlain] ;
self.tableView1 .dataSource = self;
self.tableView1 .delegate = self;

The number of sections defined as follows;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==tableView1) {
        return 12;
    } 
    else { return 10; }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath
{
    // ...... more code here
    if (tableView == self.tableView1) {     
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:CellIdentifier];        
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text=@"Cells .... ";
    } 
    else{
        // the remaining code here.. i am populating the cell as in the previous `IF` condition.
    }
}

The problem is that, i am getting only the first Table fill and not the 2nd table. Why is this? and how can i solve this ?

EDIT:
I also added the following code, hope it makes a change

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView==tableView1) {
        return 1;
    }
    else if (tableView==tableView2) { return 0; }
    else { return 0; }
}
  • 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-05-27T17:39:48+00:00Added an answer on May 27, 2026 at 5:39 pm

    Try to follow these steps in order to make the two table views having the same delegate and dataSource.

    1. Set the tag property of your table views, and #define constants on the two values. This makes the code consistent.

    2. In delegate and datasource methods you implement in your view controller subclass, test the tag property value against the constants you defined.

    3. Don’t return 0 section for a table view, it won’t display any cell at all.

    So, for example :

    #define TV_ONE 1
    #define TV_TW0 2
    
    // setting the tag property
    self.tableView1 = [[UITableView alloc]
                       initWithFrame:CGRectMake(0,0,320,100)
                               style:UITableViewStylePlain];
    self.tableView1.tag = TV_ONE;
    self.tableView1.dataSource = self;
    self.tableView1.delegate = self;
    // the same for tableView2 using TV_TWO
    
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        if (tableView.tag == TV_ONE) {
            return 1;
        }
        else if (tableView.tag == TV_TWO) {
            return 1; // at least one section
        }
        else { return 0; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a Search bar to my UITableView. I followed this tutorial:
I'm trying to add two extra rows to my UITableView. Data comes from the
I'm trying to add a custom view to an UITableView created with code from
I'm trying add a tab to my web page that looks like this: Using
I am trying to add subviews to my UITableView cells. It works just perfect
I've been trying to add a simple layer to my UITableView and it seems
I'm trying to add a UIView on top over the UITableView to mimic the
I am trying to add animation for UIImages which are added in an array.
I am trying to implement a Core Data backed UITableView that supports indexing (eg:
I'm trying to add as subview into a section in UITableView, It looks like

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.