Local notification and Open specific screen - model-view-controller

when I get local notification I want to open my specific screen.
currently in my app i have used both navigation controller as well as model view controller so at the time of navigation controller, app is switching any view but when model controller exit . it is not opening the screen.
Plz suggest any solution?

There are two way to launch app when notification comes.
1- app is running in background.then open specific screen like
- (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification
{
// write this line
[[NSNotificationCenter defaultCenter] postNotificationName:#"reloadData" object:self];
}
in which controller class you are create notification.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(reloadTable)
name:#"reloadData"
object:nil];
}
- (void)reloadTable
{
// create object of that controller which your want to open.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddToDoViewController *cvc = (AddToDoViewController *)[sb instantiateViewControllerWithIdentifier:#"AddToDo"];
[self presentModalViewController:cvc animated:YES];
}

Related

How to call a sub view from another sub view in xcode

I had a main view name "View control" and two sub views view1 and view2... My application loads with view1 as a sub view in the main view .. I had a "Next" button on main view . when I press it..view1 should be replaced with view2 with in the main view... Any idea?
You have to use NSNotificationCenter.
Assuming you have 3 views, One main view and 2 subviews.
Main view = ContainerView
Subview1= HomeViewController
Subview2= nextViewcontroller
in Subview1 use following code.
[[NSNotificationCenter defaultCenter] postNotificationName:#"ChangetoView2" object:nil];
in Subview2 use following code.
[[NSNotificationCenter defaultCenter] postNotificationName:#"ChangetoView1" object:nil];
use the below code in the init method of ContainerView.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ChangeTheView1:) name:#"ChangetoView1" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ChangeTheView2:) name:#"ChangetoView2" object:nil];
And in the same class use the following function.
- (void)ChangeTheView1:(NSNotification *)notification
{
// Change here.
[bViewcontroller.view RemoveFromSuperview];
aViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
aViewController.showLogin = NO;
[self.containerView addSubview:aViewController.view];
companyLogoImage.hidden = YES;
}
- (void)ChangeTheView2:(NSNotification *)notification
{
[aViewcontroller.view RemoveFromSuperview];
bViewController = [[SomeViewController alloc] initWithNibName:#"SomeViewController" bundle:nil];
[self.containerView addSubview:bViewController.view];
}

How to swipe the keyboard along InteractivePopGestureRecognizer?

I was wondering how to swipe the ViewController with a visible keyboard?
in iOS 7 I can swipe the ViewController from side to side, but the keyboard stays put.
in short, I would like to get to the following state:
Thanks!
Update:
I can't recommend the original solution. While it performed well (when it performed at all), it was an unreliable hack, and could easily break the pop gesture recognizer.
My colleague Dave Lyon came up with a great solution using iOS 7 view controller transitions and packaged it up into a pod:
https://github.com/cotap/TAPKeyboardPop
Once installed, just import the main file and you should be good to go.
Original:
I'd love to know if there's a better way of doing this, but I was able to achieve the behavior by adding the keyboard's view as a subview of the view controller's main view:
- (void)viewDidLoad
{
[super viewDidLoad];
self.textView.inputAccessoryView = [UIView new];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillHide:(NSNotification *)note
{
if (self.textView.isFirstResponder) {
UIView *keyboardView = self.textView.inputAccessoryView.superview;
if (keyboardView) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:keyboardView];
});
}
}
}
I've found you can also animate the keyboard with the gesture (via addTarget:action:), but the performance is abysmal and doesn't cleanly animate if the gesture is prematurely canceled.

Cocoa: ABPeoplePickerView - How can I trigger a Method upon single clicking a person?

I've looked everywhere, and hope that perhaps someone can point me in the right direction.
I just want to run a method each time the user selects a different record.
The bigger picture (in case there is an alternate way) is that when the user selects the record (single click) the persons phone numbers are to be put into a segmented control.
I've tried:
To connect an action to a button, I usually open the assistant editor, and right-click drag to the .h file. But when I'm doing it with this abpeoplepickerview I only get an Outlet connection type?
the people picker is a . 'compound view' that actually consits of a tableview, 2 buttons and a searchfield (IIRC)
answer:
you're out of luck and this component isnt suitable for you BUT of course you do some hacking:
- (void)viewDidLoad {
//you get the internal tableview
id views = [self findSubviewsOfKind:NSClassFromString(#"ABPeoplePickerTableView") withTag:NSNotFound inView:sef.peoplePickerView];
id view = [views count] ? [views objectAtIndex:0] : nil;
//subscribe to the notification
if([view respondsToSelector:#selector(selectedRow)]) {
[[NSNotificationCenter defaultCenter] addObserverForName:NSTableViewSelectionDidChangeNotification object:view queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[self peoplePickerSelectedRecordChanged:self.peoplePickerView];
}];
}
}
- (NSArray *)findSubviewsOfKind:(Class)kind withTag:(NSInteger)tag inView:(NSView*)v {
NSMutableArray *array = [NSMutableArray array];
if(kind==nil || [v isKindOfClass:kind]) {
if(tag==NSNotFound || v.tag==tag) {
[array addObject:v];
}
}
for (id subview in v.subviews) {
NSArray *vChild = [self findSubviewsOfKind:kind withTag:tag inView:subview];
[array addObjectsFromArray:vChild];
}
return array;
}
- (IBAction)peoplePickerSelectedRecordChanged:(id)sender {
NSLog(#"%#", [sender selectedRecords]);
}
ABPeoplePickerView gives notifications for exactly what you need. Look near the end of the class reference.
#implementation someController
#synthesize picker; //your ABPeoplePickerView
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// or some other method that gets called early on
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(notificate:)
name:ABPeoplePickerNameSelectionDidChangeNotification
object:picker];
}
- (void) notificate: (NSNotification*) notification {
ABPerson *person = picker.selectedRecords.firstObject;
NSLog(#"NOTIFIED %#"), person.name);
// name is a property of ABPerson I added in a category
// do what you will
}
Don't forget to remove the observer if you dismiss the window.

UIAlertview in 2 view

I have a alertview that starts in a view A and must stop in view B. How can I stop the alertview on B?
thks
How are you moving from A to B while a UIAlertView is displayed? Maybe post some code.
This scenario does not seem user-friendly, but there is a way you can dismiss the alert from A in B.
View A
Create an NSNotificationCenter and point it to a method that dismisses the alert:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissAlert) name:#"dismissAlert" object:nil];
And the notification should call something like the following:
- (void) dismissAlert:(NSNotification *)notification
{
[alertView dismissWithClickedButtonIndex: 0 animated: YES];
}
View B
Now when you want to dismiss the alert, call the notification you created in View A:
[[NSNotificationCenter defaultCenter] postNotificationName:#"dismissAlert" object:nil];
Use dismissWithClickedButtonIndex:animated:

WebView - User has scrolled

I cannot figure out how to have a WebView in Objective-c detect when a scroll has been made. I have looked at the WebFrameLoadDelegate: and found didChangeLocationWithinPageForFrame: method, but that did seem to work.
You'll want to detect the webview is scrolling by using javascript. If you do a quick google search on "uiwebview javascript" you'll see plenty of examples on how to have javascript run in the uiwebivew. Once you get the javascript to detect the scroll occurring then you have the javascript change window.location to something fake and implement the "webView:shouldStartLoadWithRequest:navigationType:" delegate to execute objective-c code. Return NO from the delegate method to not load the request.
Depends on whether you are using a UIWebView (iOS - Cocoa Touch) or WebView (OS X - Cocoa).
iOS (iOS 5 and later):
UIWebView exposes its UIScrollView, and you can set the scroll view's delegate and then implement the delegate scrollViewDidScroll: delegate method (adding to your class's #interface declaration first, of course; this example is in a UIViewController subclass):
- (void)viewDidLoad {
[super viewDidLoad];
[_webView.scrollView setDelegate:self];
}
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// do something in response to scroll
}
}
OS X:
Add an observer for the NSViewBoundsDidChangeNotification of the WebView (this example is in an NSWindowController subclass):
- (id)initWithWindowNibName:(NSString *)windowNibName {
self = [super initWithWindowNibName:windowNibName];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_scrollDetected)
name:NSViewBoundsDidChangeNotification
object:_webView];
}
return self;
}
- (void)_scrollDetected {
// do something in response to scroll
}
On OS X, you can detect it by subscribing to NSScrollViewWillStartLiveScrollNotification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(mySelector:)
name:NSScrollViewWillStartLiveScrollNotification object:nil];
I pass nil as the object parameter because when I get it, it doesn't appear to actually come from the enclosingScrollView on the WebView. And there is no scroll view property on WKWebView in Yosemite. So when handling it, you have to check if it's your web view sending it (being paranoid about type safety):
-(void)handleScroll:(id)sender
{
if ([sender isKindOfClass:[NSNotification class]])
{
NSNotification *notif = (NSNotification *)sender;
if ([notif.object isKindOfClass:[NSView class]])
{
NSView *view = (NSView *)notif.object;
if ([view isDescendantOf:self.webView])
{
//Handle scroll here
}
}
}
}
I have only tried this descendent-checking thing with WebView, so if you're using WKWebView, YMMV.
There are other scroll notifications listed in the NSScrollView documentation.

Resources