Альтернативой созданию связи является использование уведомлений.
Например, в IconHolder.h
extern const NSString* kIconHolderTouchedNotification;
В IconHolder.m
const NSString * kIconHolderTouchedNotification = @ "IconHolderTouchedNotification";
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//Here i need to call the method onPressIcon from my ViewController
[[NSNotificationCenter defaultCenter] kIconHolderTouchedNotification object:self];
}
Тогда в вашем контроллере
- (void) doApplicationRepeatingTimeChanged:(NSNotification *)notification
{
IconHolder* source = [notification object];
}
- (IBAction) awakeFromNib;
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doIconHolderTouched:) name:kIconHolderTouchedNotification object:pressedIcon];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name: kIconHolderTouchedNotification object:pressedIcon];
[super dealloc];
}
Уведомления особенно хороши, если вы хотите очень слабую связь между объектами и не нуждаетесь в двусторонней связи (т. Е. IconHolder не нужно запрашивать информацию у контроллера) или если вам нужно уведомить более одного объекта об изменениях.