I am developing am application in that,i have one requirement i.e when there is incoming call corresponding method is called.I write alertview code,its works perfectly and shows alertview.
Alertview contains two button accept and reject ,when i click any of these buttons alertview delegate methods are not called.
+ (void)incomingCallAlertView:(NSString *)string
{
UIAlertView *callAlertView=[[UIAlertView alloc] initWithTitle:string message:@"" delegate:self cancelButtonTitle:@"reject" otherButtonTitles:@"accept",nil];
[callAlertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"clickedButtonAtIndex");
if(buttonIndex==0)
{
NSLog(@"buttonindex 0");
}
else
{
NSLog(@"buttonindex 1");
}
}
I am calling the +(void)incomingcall method from another method using main thread.
- (void)showIncomingcalling
{
[CallingViewController performSelectorOnMainThread:@selector(incomingCallAlertView:) withObject:@"on_incoming_call" waitUntilDone:YES];
}
I write protocol in class ie <UIAlertViewDelegate> but the delegate methods are not called can any one solve my problem thanks in advance.
In the context of a class method,
selfrefers to the class itself, and not an instance of an object (how would a class method know about instances of the class?). So you must either make theincomingCallAlertView:method into an instance method (i. e. prefix it with a minus sign instead of a plus sign and callselfinsetad of the class name in theshowIncomingCallingmethod), or implement the delegate methods as if they were class methods:(This does work because the class object itself is an instance of its metaclass, and that means that class methods are really just instance methods of the metaclass.)
etc.
By the way, read attentively a decent Objective-C tutorial and/or language reference. This question should not have been asked here, as it’s too basic for not being looked up in other resources.