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

The Archive Base Latest Questions

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

I am trying to populate a TableView situated within a UIViewController with a collection

  • 0

I am trying to populate a TableView situated within a UIViewController with a collection of objects when a button is clicked.

The problem is that cellForRowAtIndexPath seems to be expecting ‘votes’ to be an instantiated object, which it isn’t until the button is pressed.

I’m not sure I’m going about this the correct way and would appreciate any assistance anybody could give me.

I have specified the delegate and datasource as follows:

@interface MyViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

I have completed my implementation of numberOfRowsInSection as follows:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.votes count];
}

I have completed my implementation of cellForRowAtIndexPath as follows:

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

    static NSString *CellIdentifier = @"Votes";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the region cell
    CandidatePhrase *phrase = [self.votes objectAtIndex:indexPath.row];
    cell.textLabel.text = phrase.phrase;

    return cell;

}

On button press I’m loading an array with a list of objects

_votes = [[NSArray alloc] initWithObjects:myCandidatePhrase.votes, nil];

I’m just now clear on how the table will bind each time I press the button.

Here’s the error I’m currently getting, presumably because the votes array hasn’t been instantiated?

2011-12-09 22:34:48.979 MyApp[3809:fb03] -[NSObject tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6b49b20
  • 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-27T09:39:10+00:00Added an answer on May 27, 2026 at 9:39 am

    The tableView instance (not the view controller) is going to call its delegate methods as soon as it is instantiated and whenever it is informed of a change to the table view. So it doesn’t matter if votes is instantiated or not for the delegate method to be called.

    However, if you want it to know that there are no rows when votes has not been instantiated, try this

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        if (votes != nil)
            return [self.votes count];
        else
            return 0;
    }
    

    Once you have instantiated votes, you want to call reloadData on your tableView.

    Don’t forget to add your view controller as the delegate for the tableView, if it is not already.

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

Sidebar

Related Questions

I am trying to populate the tableview with an NSMutableArray, and I am having
I'm trying to populate an NSArray with a collection of images in Resources. However,
Im trying to parse XML (which seems ok) and populate a Table View on
I am trying to populate a string with a double value using a sprintf
I'm trying to populate a TDBGrid with the results of the following TQuery against
I'm trying to populate a table with user information in a MS SQL database
I'm trying to populate a DataTable, to build a LocalReport, using the following: MySqlCommand
I'm trying to populate a dictionary dynamically in a for loop like so: pseudo-code
I'm trying to populate a List of beans from a form: public class Foo
I'm trying to populate a ComboBox programatically. I am creating ComboBoxItems and would 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.