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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:59:09+00:00 2026-05-26T00:59:09+00:00

I tried to put the delegate and the datasource of my tableview into a

  • 0

I tried to put the delegate and the datasource of my tableview into a separate class. My problem is that it always crashes with no error. This is why I can’t figure out what I’m doing wrong. Maybe someone can tell me. Maybe it is also important that I’m using ARC.

So that’s my simple code:

//ViewController.h
@interface ViewController : UIViewController {
    UITableView *myTableView;
}

@property (strong, nonatomic) IBOutlet UITableView *myTableView;

@end

//ViewController.m
#import "ViewController.h"
#import "MyTableViewDatasourceDelegate.h"

@implementation ViewController
@synthesize myTableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    MyTableViewDatasourceDelegate *test = [[MyTableViewDatasourceDelegate alloc] init];

    self.myTableView.delegate = test;
    self.myTableView.dataSource = test;
}

@end

//MyTableViewDelegateDatasourceDelegate.h
@interface MyTableViewDatasourceDelegate : NSObject <UITableViewDataSource, UITableViewDelegate>

@end

//MyTableViewDatasourceDelegate.m
@implementation MyTableViewDatasourceDelegate

-  (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return 1;
} 

- (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:@"Cell"];
    }

    cell.textLabel.text = @"Test";
    return cell;
}

@end
  • 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-26T00:59:09+00:00Added an answer on May 26, 2026 at 12:59 am

    It seems that you are not referencing test anywhere else so it gets automatically released at the end of viewDidLoad method. Make sure you implement test as an instance variable, so at least something has reference to it.

    It is not required for object to be an ivar for it to persist. Take a look at delegate property definition:

    @property(nonatomic,assign)   id <UITableViewDelegate>   delegate;
    

    The assign is crucial here, it means that this is a weak reference and UITableView won’t retain this object. Note, that if it said (nonatomic, retain) your code would work, but it was Apple’s design decision to implement it this way to avoid retain cycles.

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

Sidebar

Related Questions

I'm getting this error when I tried to put my array content into the
I've tried searching for this but it's pretty difficult to put into words. Basically,
It is hard to put this problem into words, but a real world example
I can not make TextMate2 to get my PYTHONPATH. Things I tried: Put the
Today I encountered something strange: I tried to put a utility method into an
i want to put a newline into a txt file, i tried with many
I can't find any documentation to confirm this, but it appears that you can
I found this but tried to use it and failed. How can i create
I have tried going through this Question: How Does A Delegate Work and I
I have tried to put <a href=page2.hta>Go Page 2</a> inside a .hta file. However,

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.