Delegate issue with viewcontrolller

Let me tell you my issue. I have a view controller called SubmitContentViewController where i call UploadImage method from another class called UploadQueueClass. When the view controller called SubmitContentViewController loads [self callUploadQueueClass]; gets called and then UploadImage gets called. The user is transfered to another viewcontroller called ProgressBarViewController that has a progress bar label. I need the progress bar label of ProgressBarViewController to update directly from UploadImage when the completion callback returns data in generateIDforImage method from the network query. Please check the code below.

SubmitContentViewController

@implementation SubmitContentViewController

-(void)viewDidLoad{
[self callUploadQueueClass];
}

-(void)callUploadQueueClass{
 UIViewController *myProfileView = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-3];
[self.navigationController popToViewController:myProgressViewController animated:YES];
UploadQueueClass *queue = [UploadQueueClass new]; 
[queue UploadImage];
}

@end

ProgressBarViewController

    @implementation ProgressBarViewController
    
    -(void)viewDidLoad{
    NSLog(@"ProgressBar View")
    }

-(void)viewDidAppear{
    UploadQueueClass *myClass = [[UploadQueueClass alloc]init];
myClass.delegate = self;
    }
    
//delegate method of UploadQueueClass
     -(void)uploadingStartedDelegateMethod: (UploadQueueClass *) sender{
        NSLog(@"hello from UploadQueueClass - uploading started");
    }
    
    @end

UploadQueueClass

@implementation UploadQueueClass

    -(void)generateIDforImage{
        @weakify(self)
        [[[ApiServicesProvider shared] userService] getCreatorsContentID:^(NSDictionary * _Nullable result, NSError * _Nullable error) {
            @strongify(self)
            if(nil==error){
                NSString* ccID = result.creatorsContentId;
               //here i want to update the progressBarLabel of ProgressBarViewController
            }
            else{
                self.isUploading = NO;
            }
        }];
    }

@end

So i was thinking to use delegate methods. So i created in the header file of UploadQueueClass.h a delegate method.

@class UploadQueueClass;             //define class, so protocol can see MyClass
@protocol UploadQueueClassDelegate <NSObject>   //define delegate protocol

-(void) uploadingStartedDelegateMethod: (UploadQueue *) sender;  //define delegate method to be implemented within another class
@end //end protocol

After i define the delegate method i need to set the delegate to self in ProgressBarViewController. I tried adding in ViewDidAppear of ProgressBarViewController the following code

UploadQueueClass *myClass = [[UploadQueueClass alloc]init];
myClass.delegate = self;

The problem is that when i call

self.delegate uploadingStartedDelegateMethod:(UploadQueueClass*)sender; 

in UploadQueueClass i notice that is not working. The app does not crash but the call is never triggered. I have to mention that the user is able to navigate through the app while the upload is still ongoing. So i do not know if the user is actually in ProgressBarViewController or not.

In conclusion i am trying to find a way to update the ProgressBarViewController label from UploadQueueClass at generateIDforImage method.

How can i achieve this? Any help appreciated.

This topic was automatically closed after 166 days. New replies are no longer allowed.