开发者

NSNotification issue

i want to show the alert box in my whole applicaton when we got the response from my Signin

how it is possible?

can we use 开发者_如何学GoNSNotification?


You could put a public method in your appdelegate and let it show your alertview.

You can access the app delegate like this:

[UIApplication sharedApplication].delegate

You'll need to cast it to you app delegate class to prevent a warning, then you can send the message:

[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];


- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}


It's simple to create and receive notifications:

1) Add an observer (for example, it's YourViewController) to your notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someEventHappend) 
                                                 name:@"SomeEvent" object:nil];

You should add this code in viewDidLoad method.

2) Implement someEventHappend method in YourViewController

3) Post notification when you've git response from Signin:

[[NSNotificationCenter defaultCenter] postNotificationName:@"SomeEvent" object:nil];

After that NSNotificationCenter will call someEventHappend method on YourViewController


@anil take one and set this in Global.h "BOOL Signin" value .When When it's true Then show Your alter view like this

-(void)afterSignIn
{
    if(Signin == YES)
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Meassage" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

it is not compulsory to use NSNotificationCenter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜