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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:29:26+00:00 2026-05-23T21:29:26+00:00

Note: the below is using iOS with Automatic Reference Counting (ARC) enabled. I think

  • 0

Note: the below is using iOS with Automatic Reference Counting (ARC) enabled. I think ARC may have a lot to do with why it isn’t working as this is set up as per examples i’ve found via google.

I am trying to create a protocol to notify a delegate of the filename the user selects from a UITableView.

FileListViewController.h

@protocol FileListDelegate <NSObject>
- (void)didSelectFileName:(NSString *)fileName;

@end

@interface FileListViewController : UITableViewController
{
    @private
        NSArray *fileList;
        id <FileListDelegate> delegate;
}
@property (nonatomic, retain) NSArray *fileList;
@property (nonatomic, assign) id <FileListDelegate> delegate;

@end

FileListViewController.m

#import "FileListViewController.h"

@implementation FileListViewController

@synthesize fileList;
@synthesize delegate;

This gives an error at the

@synthesize delegate;

line which is “FileListViewController.m: error: Automatic Reference Counting Issue: Existing ivar ‘delegate’ for unsafe_unretained property ‘delegate’ must be __unsafe_unretained”

If i change FileListViewController.h putting __weak and (weak) then it will run.

@protocol FileListDelegate <NSObject>
- (void)didSelectFileName:(NSString *)fileName;

@end

@interface FileListViewController : UITableViewController
{
    @private
        NSArray *fileList;
        __weak id <FileListDelegate> delegate;
}
@property (nonatomic, retain) NSArray *fileList;
@property (weak) id <FileListDelegate> delegate;

@end

But when I try to set the delegate the app crashes. A view called ‘ImportViewController’ is creating a view from ‘FileListViewController’ and setting the delegate to itself (ImportViewController) so I can implement my custom protocol of ‘didSelectFileName’. The error I get is;

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[ImportViewController setDelegate:]: unrecognized selector sent to instance 0x6c7d430’

The code I am running is;

ImportViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FileListViewController *fileListViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"filelist"];

    [fileListViewController setDelegate:self];
    [self.navigationController pushViewController:fileListViewController animated:YES];

}

My Questions are:

  • Why does putting (weak) and __weak in make it work? I don’t
    understand why this works as I found it googling and there wasn’t an
    explanation.
  • Why can’t I set my delegate using this
    ‘[fileListViewController setDelegate:self];’ ? It seems like the
    compiler doesn’t know ‘delegate’ exists.
  • 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-23T21:29:29+00:00Added an answer on May 23, 2026 at 9:29 pm

    It seems that with :

    FileListViewController *fileListViewController =
        [self.storyboard instantiateViewControllerWithIdentifier:@"filelist"];
    

    you didn’t get an FileListViewController object. Look at the message it says :

    -[ImportViewController setDelegate:]: unrecognized selector sent to instance 0x6c7d430

    and that why your app crashes. Also try to define a retain property, instead of just assign, in case the delegate is deallocated elsewhere, your app won’t crash.

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

Sidebar

Related Questions

Please note the Edit below for a lot more information, and a possible solution
Note The question below was asked in 2008 about some code from 2003. As
Please note: In each step I describe below I'm logged in as the same
NOTE: I am not set on using VI, it is just the first thing
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note that I am not asking which to choose (MVC or MVP), but rather
Note : The code in this question is part of deSleeper if you 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.