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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:52:17+00:00 2026-05-31T11:52:17+00:00

I have been working on this problem for close to 4 days now. I

  • 0

I have been working on this problem for close to 4 days now.

I am at the point where I think its not so much a problem with my code, but the structure of my application that is causing the issue.

I am trying to implement protocols and delegates to get an array from one NSObject(class) to a ViewController.

my code is pretty much line by line copied from this tutorial the only differences are in the face I have ARC turned on so have had to replace (nonatomic, retain) to (strong) and have not used dealloc 🙂

so with that being said its still not passing the data back to the viewcontroller. (highly annoying) I have tried dozens of different combinations of solutions that I have had help with and nothing has worked. This has lead me to believe that maybe there is an error in the structure of my application or the way things have been initialized etc, which I will attempt to explain now.

When my viewcontroller with tableview loads the viewdidload method called the delegate of my parser class, then once the first cell of the tableview has loaded it called my connection class and tells it to download some data from the server.
Inside my connection class I use NSURLConnection delegates from the apple library, in the delegate method connectionDidFinishLoading the data that has been downloaded is passed over to my parser class (however this is where i think its going wrong because i declare the object again.. which i think is where things are going amiss)

this is how I call my parser class from my connection class.

parserClass *myparser = [[EngineResponses alloc] init];
[myparser  ReciveResponse:receivedData];

then once the data is in my parser class it gets parsed and then I try to pass the data across to my viewcontroller.. but its never accessing that delegate method that I set up.

Hopefully this is where the problem is because I just dont know where else I am going wrong.
what do you think?

UPDATE: heres my code –

ViewController.h

#import "EngineResponses.h" //delegates & protocols

interface SearchViewController : UITableViewController <PassParsedData> {

//delegates to parser class
    EngineResponses *engineResponses;
//..

ViewController.m

#import "EngineResponses.h"

//this is where I set up the delegate/protocol for the parser class
- (void)viewDidLoad
{
    [super viewDidLoad];

//..
engineResponses = [[EngineResponses alloc] init];
[engineResponses setMydelegate:self];
//..
}

//this is where i set up and call the connection class
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//..
if(indexPath.section == 0){        
    //..
    if (indexPath.row == 0){
     EngineRequests *engineRequests = [[EngineRequests alloc] init];
                [engineRequests initalizePacketVariables:0 startCode:@"myReg" activationCode:@"myAct" methodName:@"GetStuff"];
                //..
}

#pragma - Reciver methods

- (void)sendArray:(NSArray *)array
{
    ICMfgFilterArray = array;
    [self.tableView reloadData]; 
}

EngineRequests.m

//connection delegates etc..
//then I pass the data from the connection delegates over to the parser class
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{   
    EngineResponses *engineResponses = [[EngineResponses alloc] init];
    [engineResponses  ReciveResponse:receivedData];
}

EngineResponses.h

@protocol PassParsedData
- (void)sendArray:(NSArray *)array;
@end

//..
id <PassParsedData> mydelegate;
//..
@property (strong) id  <PassParsedData> mydelegate; 

EngineResponses.m

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
//..
    [[self mydelegate]sendArray:filteredArray];    
}

1

  • 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-31T11:52:19+00:00Added an answer on May 31, 2026 at 11:52 am

    Allright. I will re-do it based on your updated code. To make it easy I copy your code and do the amendments.

    ViewController.h

    #import "EngineResponses.h" //delegates & protocols
    
    interface SearchViewController : UITableViewController <PassParsedData> {
    
    //delegates to parser class
        EngineResponses *engineResponses;
    
        EngineRequests *engineRequests;  
    //..
    

    Explanation:
    You are using ARC. If you define the pointer locally, as you did before, and to not
    retain it – which you can’t because of ARC – then it will be released directly after its
    creation. You will have to keep at least one reference to the object.
    Bare in mind that ARC means Automatic Reference Counting. As soon as there is no
    reference to an object it will be released.
    This proposal with the engineRequests object defined here only works while you
    submit only one request at a time. If you have several requests, i.e. for more than one cell or
    whatver, then you may go for a mutable array or mutable dictionary where you keep the requests while you use them.

    ViewController.m

    #import "EngineResponses.h"
    
    //this is where I set up the delegate/protocol for the parser class
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
    //..
    engineResponses = [[EngineResponses alloc] init];
    [engineResponses setMydelegate:self];
    
    engineRequests = [[EngineRequests alloc] init];  // Use instance variable instead of local variable
    [engineRequests setEnineResponses:engineResponses];
    
    //..
    }
    
    //this is where i set up and call the connection class
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    //..
    if(indexPath.section == 0){        
        //..
        if (indexPath.row == 0){
         [engineRequests initalizePacketVariables:0 startCode:@"myReg" activationCode:@"myAct" methodName:@"GetStuff"];
                    //..
    }
    
    #pragma - Reciver methods
    
    - (void)sendArray:(NSArray *)array
    {
        ICMfgFilterArray = array;
        [self.tableView reloadData]; 
    }
    

    Explanation: The engineRequets is now an instance varaible and should not be re-defined locally.
    You could define a variable of the same name locally which would hide the instance variable. I think
    in that case you get a compiler warning but that will work and will most probably confuse you.
    Again, if you use more than one request at a time then this solution will not work!

    EngineRequests.h

    EngineResponses *engineResponses;
    

    EngineRequests.m

    @synthesize engineResponses;
    
    //connection delegates etc..
    //then I pass the data from the connection delegates over to the parser class
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {   
        //EngineResponses *engineResponses = [[EngineResponses alloc] init]; //This Object has already been created! 
        [engineResponses  ReciveResponse:receivedData];
    }
    

    Explanation: Here, too, the reference to EngineResponses is now an instance variable, not a locally defined one. The object will not be newly created but it references to that very object that was created in the view controller. That is the one EngineResponses that ‘knows’ its view controller object and can therefore pass back the parsed data.

    EngineResponses.h

    @protocol PassParsedData
    - (void)sendArray:(NSArray *)array;
    @end
    
    //..
    id <PassParsedData> mydelegate;
    //..
    @property (strong) id  <PassParsedData> mydelegate; 
    

    EngineResponses.m

    - (void)parserDidEndDocument:(NSXMLParser *)parser
    {
    //..
        [[self mydelegate]sendArray:filteredArray];    
    }
    

    … give it a try 🙂

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

Sidebar

Related Questions

I have been working on this problem for 2 days now and it's an
I have been working on this problem for a while now. I am trying
I have been working on this for days but I don't get it so
I have been working on this for 24 hours now, trying to optimize it.
So I have been working on this project for a short while now. I
Ok, I have been working on solving this problem all day, and I am
Have been working on this question for a couple hours and have come close
Alright, some of you might have noticed I've been working on this problem off
I have been working on this for the greater part of the day and
I have been working on Flex for last couple of months and as this

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.