«Test» вызывает [делегат onSignal: nil], затем мы убиваем «тестовый» объект. «тестовый» объект не достиг конца функции onSignal. (Это плохо?)
@implementation FirstViewController
@synthesize array;
- (void)viewDidLoad
{
[super viewDidLoad];
self.array = [[[NSMutableArray alloc] initWithCapacity:20] autorelease];
Test *test = [[Test alloc] init];
test.delegate = self;
[array addObject:test];
[test release];
}
-(void) onSignal:(id)sender
{
[array removeObjectAtIndex:0];
}
и тест
@protocol TestDelegate <NSObject>
-(void) onSignal:(id) sender;
@end
@interface Test : NSObject
@property (nonatomic, assign) id<TestDelegate> delegate;
-(void) signal:(id) sender;
@end
@implementation Test
@synthesize delegate;
- (id)init
{
if (self = [super init])
{
[self performSelector:@selector(signal:) withObject:nil afterDelay:5];
}
return self;
}
-(void) signal:(id) sender
{
[delegate onSignal:nil];
}