Giter VIP home page Giter VIP logo

ayslidingpickerview's Issues

AYSlidingPickerView is not moved to back

Hi,
My use case is quite simple:
I have 2 view controllers let say A, B (A is in a navigation controller). Flow is:

  • From A I tap a button to display B to create a new data record.
  • From B I tap another button to dismiss B and add that record to A's property (NSMutableArray*).
  • In A's viewWillAppear I check if number of records > 0 then I add them to AYSlidingPickerView

The problem is:

  • If I display B using [A.navigationController pushViewController:animated:] then AYSlidingPickerView works normally.
  • If I display B using [A presentViewController:animated:completion:] then when B is dismissed the AYSlidingPickerView will be displayed above A so I can not do anything with A anymore.

My fix:
For now to fix it I put AYSlidingPickerView to back again in [A viewDidAppear:] as shown in code below but I feel like a hack so I hope you can take a look and suggest a better fix.

Code of A:

#import "ViewController.h"
#import "ItemViewController.h"
#import <AYSlidingPickerView/AYSlidingPickerView.h>

@interface ViewController () {
    NSMutableArray *texts;
    AYSlidingPickerView *pickerView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    texts = [[NSMutableArray alloc] init];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if ([texts count] > 0) {
        pickerView = [AYSlidingPickerView sharedInstance];

        NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:[texts count]];
        for (NSString *s in texts) {
            AYSlidingPickerViewItem *item = [[AYSlidingPickerViewItem alloc] initWithTitle:s handler:^(BOOL completed) {
                self.navigationController.title = s;
            }];
            [items addObject:item];
        }
        pickerView.mainView = self.view;
        pickerView.items = items;
        pickerView.selectedIndex = 0;
        pickerView.closeOnSelection = YES;
        [pickerView addGestureRecognizersToNavigationBar:self.navigationController.navigationBar];
    }

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // To ensure picker view is sent to back
   [[UIApplication sharedApplication].delegate.window sendSubviewToBack:pickerView];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [pickerView removeGestureRecognizersFromNavigationBar:self.navigationController.navigationBar];
}

- (IBAction)addItem:(id)sender {
    ItemViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"ItemViewController"];
    ivc.texts = texts;
    [self presentViewController:ivc animated:YES completion:nil];
//    [self.navigationController pushViewController:ivc animated:YES];

}

Code of B:

#import "ItemViewController.h"

@interface ItemViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textToAdd;

@end

@implementation ItemViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateStyle:NSDateFormatterFullStyle];

  self.textToAdd.text = [formatter stringFromDate:[NSDate date]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)addItemTapped:(id)sender {
  [self.texts addObject:self.textToAdd.text];
  [self dismissViewControllerAnimated:YES completion:nil];
//    [self.navigationController popViewControllerAnimated:YES];
}

@end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.