Opening app from extension, properties only change the first time - ios

I have a today widget extension, and when I click a button it opens up the app. The first time I click the button and follow the code through, it uses a custom URL scheme to pass data through. That's parsed in the AppDelegate, and it figures out what data to populate the ViewController with. The ViewController is instantiated with a storyboard ID. Values are applied to one of the ViewController's properties, and then in the viewDidLoad the rest of the values are populated based on this passed in Value. This all works the first time.
However, if I hit the home button, open notification center, tap a button in my app and go through the whole process for a second time.. I step through the code as normal, all the values get set, but when the ViewController gets displayed, the values (such as UILabel) are the same as the first time, but they should have changed.
NSString *url = [NSString stringWithFormat:string ://%#", self.expanededTubeLine.lineName ];
NSExtensionContext *myExtension=[self extensionContext];
[myExtension openURL:[NSURL URLWithString:url] completionHandler:nil];
//
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSString *tubeLineName = [url host];
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.koc.extensiontest"];
if ([defaults objectForKey:#"weekendData"]) {
NSData *tubeData = [[defaults objectForKey:#"weekendData"] copy];
TFLParser *parser = [[TFLParser alloc] initWithData:tubeData];
[parser parseData];
for (int x = 0; x < parser.delayedTubeLines.count; x++) {
TubeLine *tl = [[TubeLine alloc] init];
tl = [parser.delayedTubeLines objectAtIndex:x];
if ([tl.lineName isEqualToString:tubeLineName]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
TubeLineViewController *tubeLineViewController = [storyboard instantiateViewControllerWithIdentifier:#"TubeLineViewController"];
tubeLineViewController.tubeLine = tl;
[self.window.rootViewController presentViewController:tubeLineViewController animated:YES completion:nil];
return YES;
}
}
}
}
//
- (void)viewDidLoad {
[super viewDidLoad];
self.tubeLineName.text = self.tubeLine.lineName;
self.tubeLineName.font = [UIFont openSansLightFontOfSize:18.0f];
self.tubeLineName.textColor = [UIColor whiteColor];
self.tubeLineName.backgroundColor = self.tubeLine.lineBackgroundUIColor;
self.tubeLineName.layer.cornerRadius = 5;
self.tubeLineName.clipsToBounds = YES;
self.tubeLineMessage.font = [UIFont openSansLightFontOfSize:18.0f];
self.tubeLineMessage.text = self.tubeLine.lineMessage;
self.tubeLineMessage.textColor = [UIColor darkGrayColor];
}

It sounds like the View is loaded already so pop all the view controllers before pushing the widget based controller in handleOpenURL: function.
[self.viewController.navController popToRootViewControllerAnimated:NO];
if ([self.viewController presentedViewController]) {
[self.viewController dismissViewControllerAnimated:NO completion:nil];
}

Related

Side Out Menu didn't clickable in Ipad pro IOS 11-inch obj c

I faced a problem in my objective c code,
I have a side menu,
the side menu works successfully on all devices except the Ipad pro-11-inch,
but in (Ipad pro-11-inch) all table view methods work successfully except "didSelectRowAtIndexPath"
I didn't know the is the problem,
This is some of my code:
in appdelegate.m:
[[ApplicationDelegate window] setRootViewController: [storyboard instantiateInitialViewController]];
[[SlideNavigationController sharedInstance] initWithRootViewController:destinationViewController];
// SlideNavigation Width
int num = isTargetedSize ? 3 : 2;
CGFloat portraitSlideOffset = [UIScreen mainScreen].bounds.size.width / num;
// SlideNavigation
UIViewController *viewController = (SlideOutMenuViewController *)[storyboard instantiateViewControllerWithIdentifier: #"SlideOutMenuViewController"];
[[SlideNavigationController sharedInstance] setLeftMenu: viewController];
[[SlideNavigationController sharedInstance] setMenuRevealAnimationDuration: 0.25f];
[[SlideNavigationController sharedInstance] setEnableSwipeGesture:YES];
[[SlideNavigationController sharedInstance] setPortraitSlideOffset:portraitSlideOffset];
in SlideOutMenuViewController.h
- (void)viewDidLoad {
[super viewDidLoad];
//
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
modulesArray = [defaults objectForKey:#"modulesArray"];
NSLog(#"viewDidLoad_Slide");
//
[self mapAuthModules];
// Auto resize table view cell
self.tableView.rowHeight = UITableViewAutomaticDimension;
// self.tableView.rowHeight = 44;
// self.tableView.cancelsTouchesInView = false
//
serviceGroup = dispatch_group_create();
}
how can i solve this problem?
in SlideNavigationController you have to add this line
[self.view.superview insertSubview:menuViewController.view atIndex:0];

xcode 8 created a second controller as a popup but just get black screen

I've tried using similar answers to my problem that i've encounter. I'm new to Xcode and I have one controller that contains a uiwebview that loads my website. i have coding to detect if a certain link is pressed. The issue i'm running into is when a certain link is pressed, I need my second controller to act as a pop up and display a different webpage. Everything works and that link is pressed my NSLog says that it in the second controller but the display is black. Here code that i have in the main view controller that loads my webpage:
- (void)viewDidLoad {
[super viewDidLoad];
self.webViewer.delegate=self;
NSString *fullURL = #"https://www.example.com?first_run=true";
NSURL *url = [NSURL URLWithString:fullURL];
//NSLog(#"first page loaded=%#",url);
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];
[_webViewer loadRequest:requestObj];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.webViewer.delegate=self;
NSURL *strurl = request.URL;
NSString *urlString = strurl.relativeString;
NSLog(#"link clicked=%#",urlString);
if(//not the right link do this){
}
else{//is the right link do this
NSLog(#"found");
self.popup = [[PopUpController alloc] init];
[self.popup showInView:self.view animated:YES];
return NO;
}
}
#end
then for my second controller it's supposed to load a different webpage but just get a black screen:
- (void)viewDidLoad {
self.popupView.delegate=self;
NSString *popupURL = #"https://www.example2.com";
NSURL *url_popup = [NSURL URLWithString:popupURL];
NSLog(#"popup page loaded=%#",url_popup);
NSURLRequest *requestObj2 = [NSURLRequest requestWithURL: url_popup];
[_popupView loadRequest:requestObj2];
}
- (void)showAnimate{
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3);
self.view.alpha = 0;
[UIView animateWithDuration:.25 animations:^{
self.view.alpha = 1;
self.view.transform = CGAffineTransformMakeScale(1, 1);
}];
}
- (void)showInView:(UIView *)aView animated:(BOOL)animated{
CGFloat x = self.view.center.x - (aView.frame.size.width);
CGFloat y = self.view.center.y - (aView.frame.size.height);
[aView setFrame:CGRectMake(x,y,aView.bounds.size.width,aView.bounds.size.height)];
[aView addSubview:self.view];
if (animated) {
[self showAnimate];
}
}
Any help would be extremely appreciated. I've tried for 3 weeks searching and trying different solutions found on this forum but they all didn't work for mine. Not sure if I'm just not instantiating my controllers right or some piece of code that I'm missing. Thank you for your time in advanced.
This line:
self.popup = [[PopUpController alloc] init];
simply creates an instance of PopUpController but doesn't load any of you UI elements with it.
Assuming you have designed PopUpController in storyboards, give it an Identifier such as "MyPopUp"
and then use:
// storyboard reference
UIStoryboard *storyboard = [UIStoryboard storyboardWithName: #"Main" bundle:[NSBundle mainBundle]];
// instantiate PopUpController from the storyboard
self.popup = (PopUpController *)[storyboard instantiateViewControllerWithIdentifier:#"MyPopUp"];
// show it
[self presentViewController:self.popup animated:YES completion:nil];

How to display message in UITableView under certain conditions

I have a UITableView inside of an UITabBarController. Now, I am already checking to see if a user is logged in, and if they are not logged in I display a Modal View Controller to have them log in or sign up. But here's my problem, when the user hit's cancel, the user goes back to the original position of the table view. I can't have users see the rows in table view if they are not signed in. If a user is not logged in, I want a message exactly how the examples Apple gives in the iTunes store and the "Popular near me" examples in the Apple Human Interface Guideline:
https://developer.apple.com/library/iOS/documentation/userexperience/conceptual/mobilehig/StartingStopping.html#//apple_ref/doc/uid/TP40006556-CH52-SW1
So how would I display a message like that in a tableview controller? Keep in mind, I will always have data for that table view controller. Hopefully I am clear for everyone. Would I just bring the tableview background to the front of the tableview rows?
// ATableViewController embedded in a NavigationController with UITabBar
- (void)viewWillAppear:(BOOL)animated
{
// NSLog(#"dateViewDidLoad %f", [[NSDate date] timeIntervalSince1970]);
[super viewWillAppear:animated];
NSUserDefaults *textDef = [NSUserDefaults standardUserDefaults];
NSString *userName = [textDef stringForKey:#"userName"];
if (userName == nil) {
SignUpViewController *signup = [[SignUpViewController alloc]initWithNibName:#"SignUpViewController" bundle:nil];
[signup setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:signup animated:YES completion:nil];
// Display message you need to sign in to view this content
} else {
// Proceed and display the rows
}
}
If you use a UITableViewController you could "abuse" tableHeaderView of the tableView, by resizing it to full screen and disabling the dataSource methods and scrolling.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (isLoggedIn) {
self.tableView.tableHeaderView = nil;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.scrollEnabled = YES;
[self.tableView reloadData];
}
else {
if (!self.tableView.tableHeaderView) {
UIView *viewToDisplayIfNotLoggedIn = [[UIView alloc] initWithFrame:self.view.bounds];
viewToDisplayIfNotLoggedIn.backgroundColor = [UIColor redColor];
self.tableView.tableHeaderView = viewToDisplayIfNotLoggedIn;
}
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
self.tableView.scrollEnabled = NO;
[self.tableView reloadData];
}
}
If you are using a normal UIViewController it's even easier than that, just hide the tableView and show another UIView:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (isLoggedIn) {
self.tableView.hidden = NO;
self.viewToDisplayIfNotLoggedIn.hidden = YES;
}
else {
self.tableView.hidden = YES;
if (!self.viewToDisplayIfNotLoggedIn) {
self.viewToDisplayIfNotLoggedIn = [[UIView alloc] initWithFrame:self.view.bounds];
self.viewToDisplayIfNotLoggedIn.backgroundColor = [UIColor redColor];
[self.view addSubview:self.viewToDisplayIfNotLoggedIn];
}
self.viewToDisplayIfNotLoggedIn.hidden = NO;
}
}

IOS - toolbar is not appearing on top

i have asked this question here also but i didn't get any solution.so i am asking here again with the full explanation.
I downloaded EPub Reader library from here. When i run this library,first comes a table view which contain four rows having values EPUB ,PDF etc and after clicking on the "EPUB" row
book appears successfully with the top toolbar. Because i have to load the book first in start instead of showing the toolbar i did some changes with the code. copied some code from didSelectRowAtIndexPath and added that code into delegate.m. so now the problem is book is successfully loading but the toolbar is not showing up
here is my code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [userDefaults objectForKey:#"AppleLanguages"];
EPubViewController *epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"AtoZbook" ofType:#"epub"]]];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:epubView];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
the code of loading epubView was in RootViewController.m in the original library
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
//TXT
case 0:{
//txt
}
break;
//PDF
case 1:{
//PDF
}
break;
//EPUB
case 2:{
epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"The Chessmen of Mars" ofType:#"epub"]]];
epubView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:epubView animated:YES];
[epubView release];
}
break;
case 3:{
//another book
}
break;
default:
break;
}
}
here is my view didLoadMethod of EpubViewController
- (void)viewDidLoad {
[super viewDidLoad];
loadingIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
loadingIndicator.center = CGPointMake(toolbar.frame.size.width/2 ,toolbar.frame.size.height/2);
[loadingIndicator startAnimating];
toolbar.alpha = 0.8;
[self.toolbar addSubview:loadingIndicator];
[webView setDelegate:self];
UIScrollView* sv = nil;
for (UIView* v in webView.subviews) {
if([v isKindOfClass:[UIScrollView class]]){
sv = (UIScrollView*) v;
sv.scrollEnabled = NO;
sv.bounces = NO;
}
}
currentTextSize = 100;
//Webview
UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(gotoNextPage)] ;
[rightSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(gotoPrevPage)] ;
[leftSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[webView addGestureRecognizer:rightSwipeRecognizer];
[webView addGestureRecognizer:leftSwipeRecognizer];
[self performSelector:#selector(stratRolling)];
}
here are the images
i want to say again that the toolbar works fine when i show the epubViewController from the Case 2 i mean by clicking the row if i have to show the table view first.
your tool bar is hiding being navigation bar since navigation bar is always on top you can add your tool bar as sub view of navigation bar i m not sure if it will work though best approch is use navigation bar and add item it it like left button right button and title stuff or you can add a view as subview of navigation bar i have done that before sample code
navBar=self.navigationController.navigationBar;
[navBar addSubview:statusBar];
statusBar.frame=f;
self.navigationController.navigationBar.translucent = YES;
here statusBar was a view was set up like your tool bar same size.

I am trying to implement NIPhotoScrollView but My code is not working ie data source methods and delegate methods are not being called

I have been trying to implement NIPhotoAlbumScrollView http://jverkoey.github.com/nimbus/interface_n_i_photo_album_scroll_view.html. I am using photos in app bundle. But this code is not working. Here is link of full code http://pastebin.com/ysvPL6ee
AlbumViewController.h
#interface AlbumViewController : NIToolbarPhotoViewController <NIPhotoAlbumScrollViewDataSource>
{
NSMutableArray* photoInformation;
}
#end
#import "AlbumViewController.h"
#implementation AlbumViewController
#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
photoInformation = [[NSMutableArray alloc] init];
for(int i=0; i<2; i++)
{
NSString* originalImageSource = #"Photo001.jpg";
NSString* thumbnailImageSource = #"img1.jpg";
NSDictionary* prunedPhotoInfo = [NSDictionary dictionaryWithObjectsAndKeys:
originalImageSource, #"originalSource",
thumbnailImageSource, #"thumbnailSource",
nil];
[photoInformation addObject:prunedPhotoInfo];
}
self.photoAlbumView.dataSource = self;
self.title = NSLocalizedString(#"Loading...", #"Navigation bar title - Loading a photo album");
[self.navigationController setNavigationBarHidden:NO];
[self.photoAlbumView reloadData];
}
Edit
Not working means - It does not load images and not even show loading image
self.photoAlbumView.loadingImage = [UIImage imageWithContentsOfFile:
NIPathForBundleResource(nil, #"img1.jpg")];
The - (NSInteger)numberOfPagesInPagingScrollView:(NIPagingScrollView *)pagingScrollView or any other methods are not being called.
I forgot to add [super loadView] at the beginning of the loadView method.
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
[super loadView];
photoInformation = [[NSMutableArray alloc] init];
for(int i=0; i<2; i++)
{
NSString* originalImageSource = #"Photo001.jpg";
NSString* thumbnailImageSource = #"img1.jpg";
NSDictionary* prunedPhotoInfo = [NSDictionary dictionaryWithObjectsAndKeys:
originalImageSource, #"originalSource",
thumbnailImageSource, #"thumbnailSource",
nil];
[photoInformation addObject:prunedPhotoInfo];
}
self.photoAlbumView.dataSource = self;
self.title = NSLocalizedString(#"Loading...", #"Navigation bar title - Loading a photo album");
[self.navigationController setNavigationBarHidden:NO];
[self.photoAlbumView reloadData];
}

Resources