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

  • Home
  • SEARCH
  • 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 8018667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:10:55+00:00 2026-06-04T21:10:55+00:00

I have a UIViewController that I want to use to implement the methods of

  • 0

I have a UIViewController that I want to use to implement the methods of UITableViewDataSource on. I have this header, FriendsController.h:

#import <UIKit/UIKit.h>
@interface FriendsController : UIViewController <UITableViewDataSource>
@end

Edit: now updated the @interface declaration to:

@interface FriendsController : UIViewController <UITableViewDataSource, UITableViewDelegate>

and this implementation, FriendsController.m:

#import "FriendsController.h"

@implementation FriendsController

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section
{
  // Return the number of rows in the section.
  NSLog(@"CALLED .numberOfRowsInSection()");
  return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSLog(@"CALLED cellForRowAtIndexPath()");
  UITableViewCell *cell = [tableView
                             dequeueReusableCellWithIdentifier:@"FriendCell"];
  cell.textLabel.text = @"Testing label";
  return cell;
}
@end

When run this gives me a ‘-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x81734d0‘. Can anyone see if there is something wrong with my implementation/declaration of .numberOfRowsInSection()?

Edit: I’ve added a technique for method listing from here and run the view ‘unconnected’, it outputs the following list:

[<timestamp etc>] Method no #0: tableView:numberOfRowsInSection:
[<timestamp etc>] Method no #1: tableView:cellForRowAtIndexPath:
[<timestamp etc>] Method no #2: numberOfSectionsInTableView:
[<timestamp etc>] Method no #3: tableView:didSelectRowAtIndexPath:
[<timestamp etc>] Method no #4: viewDidLoad

Post scriptum: Both @ThisDarkTao and @Pei got it right, as can be seen in my previous question documenting the visual parts, here.

  • 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-04T21:10:55+00:00Added an answer on June 4, 2026 at 9:10 pm

    You need to add UITableViewDelegate to the list of protocols in the interface file, like this: <UITableViewDataSource, UITableViewDelegate>

    You also need all of the following delegate methods:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 1; // Number of rows
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        cell.textLabel.text = @"Test Cell";
    
        return cell;
    }
    

    In your xib/storyboard view, you also need to connect the tableview’s delegate and datasource connections to the viewcontroller.

    If you want your cells to ‘do something’ when you tap them, you also need to implement the following delegate method:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"Tapped cell %d",indexPath.row);     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In iOS4, I want to use MPMoviePlayerController. I have a UIViewController that I pass
I have several subclasses of UIViewController that I want to use a single category
I have a UIView associated with it's own UIViewController that I want to always
I have a function that returns a NSUrl, and i want to use it
I have an image that I want to use as the background of my
I have several IBOutlet and use them with IBOutletCollection : @interface IBOutletCollectionViewController : UIViewController
I have a button that, when selected, I want to use it to display
I have a UIViewController with its own .xib, and I want to use a
I have UISplitViewController that I want to be updated from a UIViewController that is
So I have a UIViewController that has a UITabBar in the view. I want

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.