Reputation: 1191
I'm new to objective c and trying to grasp the delegate methology and usage. Currently i have Alertview class, and i need it to make a another class to call function of its. I'v managed to do the same with with appdelegate class. But can't do it with my own class.
TableViewController *newControll = (TableViewController*)[UIApplication sharedApplication].delegate;
[newControll openSettings];
That's how I'm trying to access my method. Compilator see's this method in newControll, yet calling this gets unrecognizet selector.
Basicaly i need to call a function of which was already created earlier, from another class. I'm sorry if this is a simple solution, but i just can't grasp delegate and objective-c quite well yet.
Maybe not everyone get's what I need to do, so i'll try to explain once more.
I have object TableViewController
. From this object inside I'm calling class AlertView
to display some alert message. And accordingly to user interaction in alert dialogs (password is ok, password isn't) I need to call method openSettings
in my TableViewController
or not call. So how to do this?
Upvotes: 0
Views: 91
Reputation: 23278
If your TableViewController
is not your appdelegate class, you should use the object of TableViewController
to use the method openSettings
.
It should be something like,
TableViewController *newControll = [[TableViewController alloc] init];
Assuming that you are moving to a new alertView
. In your AlertView.h
file add,
@property(nonatomic, retain) TableViewController *tableViewController;
And while creating the new alertView
object,
AlertView *alertView = [[AlertView alloc] init];
//some code..
alertView.tableViewController = self;
Now in your AlertView
class, call it as,
[self.tableViewController openSettings];
Usage of appdelegate is not the way to do it.
If you need some tutorials on iOS, check raywenderlich.
Upvotes: 1