Question

I have a helper class called FunctionHelper.m.

I implemented some methods I would like to reuse. One of them is giving me some issues.

+(UIActivityIndicatorView *) InitActivityIndicator{
    UIActivityIndicatorView *activityIndicator  = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
                                                   UIActivityIndicatorViewStyleWhiteLarge];

    //[activityIndicator setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0)];
    activityIndicator.hidesWhenStopped = YES;
    activityIndicator.color = [UIColor redColor];
    //[self.view addSubview:activityIndicator];

    return activityIndicator;
}

I am not able to compile the code, when I try to access the View size or add a view.

The function is working as is, Im just not able to manipulate. I tried inheriting from UIViewController but it did not help. Please advice.

Was it helpful?

Solution

I assume you put this method in the helper class, because you may want to use this for different view controllers.

So i would suggest to change for your method like this

+(void) AddActivityIndicatorOnView: (UIView *)view{
    UIActivityIndicatorView *activityIndicator  = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
                                               UIActivityIndicatorViewStyleWhiteLarge];

    [activityIndicator setCenter:CGPointMake(view.frame.size.width/2.0, view.frame.size.height/2.0)];
    activityIndicator.hidesWhenStopped = YES;
    activityIndicator.color = [UIColor redColor];
    [view addSubview:activityIndicator];
}

So whenever you need to add the activity Indicator, simply pass the view into the method like this

[FunctionHelper AddActivityIndicatorOnView:self.view];

I don't know if i understand your questions correctly, if there is anything missing, feel free to leave in the comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top