BarButtonItem With Popovercontroller? - ios

I have a BarButtonItem and a Popovercontroller. the question is who can i pop something when i click on the button can some one help me. i will post some code what i have on this moment.
-(void) showPop:(id)sender{
NSLog(#"test");
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:popover];
[pop setDelegate:self];
[pop presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//self.title = NSLocalizedString(#"Nieuws", #"Nieuws");
/*if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}*/
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_loading = NO;
self.title = #"Agenda";
if (_refreshHeaderView == nil) {
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
}
// update the last update date
self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
if ([self.navigationController.navigationBar respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Bar-bg.png"] forBarMetrics:UIBarMetricsDefault];
}
[_refreshHeaderView refreshLastUpdatedDate];
self.tableView.contentInset = UIEdgeInsetsMake(66.0f, 0.0f, 0.0f, 0.0f);
[_refreshHeaderView egoRefreshScrollViewDidEndDragging: self.tableView];
//[self loadData];
//[popButton addTarget:self action:#selector(showPop:) forControlEvents:UIControlEventTouchUpInside];
button = [[UIBarButtonItem alloc] initWithTitle:#"Filter" style:UIBarButtonItemStyleBordered target:self action:#selector(showPop)];
self.navigationItem.leftBarButtonItem = button;
}

Might just be a typo but when you create your button, the selector should be showPop: (with a colon) not showPop.

Related

Navigation Bar's Button Item Not Clickable on iPad

In my app, I use the old GKImage library for adding pictures and being able to custom crop them easily. This works pretty well, except when it comes to iPad. On iPhone, everything works great. The main issue is this:
When I use an iPad, none of the barButtonItems are clickable.
Here is my code for this view:
- (void)_actionCancel{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)_actionUse{
NSLog(#"PRESSED");
_croppedImage = [self.imageCropView croppedImage];
[self.delegate imageCropController:self didFinishWithCroppedImage:_croppedImage];
}
- (void)_setupNavigationBar{
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(_actionCancel)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Use"
style:UIBarButtonItemStylePlain
target:self
action:#selector(_actionUse)];
}
- (void)_setupCropView{
self.imageCropView = [[GKImageCropView alloc] initWithFrame:self.view.bounds];
[self.imageCropView setImageToCrop:sourceImage];
[self.imageCropView setResizableCropArea:self.resizeableCropArea];
[self.imageCropView setCropSize:cropSize];
[self.view addSubview:self.imageCropView];
}
#pragma mark -
#pragma Super Class Methods
- (id)init{
self = [super init];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
self.title = #"Choose Photo";
[self _setupNavigationBar];
[self _setupCropView];
[self.navigationController setNavigationBarHidden:NO];
}
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.imageCropView.frame = self.view.bounds;
}
The code used to present this controller is:
self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(280, 280);
self.imagePicker.delegate = self;
self.imagePicker.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.imagePicker.imagePickerController animated:YES completion:nil];
Is it an issue with presenting the view controller?

How to remove UINavigationController / UINavigationBar background in objective-c?

I have 2 ViewController and first one is rootviewcontroller for NavigationController. I want to remove background of navigationbar in second viewcontroller and just show my navigationitem at top.
How to do that ? and what I should to do when I pop second viewcontroller, navigationbar have its old background not the secendview controller background ?
here is my code :
#implementation testView1
- (void)viewDidLoad
{
[super viewDidLoad];
[button addTarget:self action:#selector(ClickAction) forControlEvents:UIControlEventTouchUpInside ];
self.navigationController.navigationBar.translatesAutoresizingMaskIntoConstraints = false;
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationItem.title = #"Home";
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor whiteColor]};
}
-(void)ClickAction
{
testView2 *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"V2"];
[self.navigationController pushViewController:detail animated:YES];
}
#implementation testView2
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
self.title = #"No";
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.backgroundColor = nil;
self.navigationController.navigationBar.tintColor = nil;
self.navigationController.view.tintColor = nil;
self.navigationController.view.backgroundColor = nil;
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"left-arrow.png"] style:UIBarButtonItemStylePlain target:self action:#selector(Back:)];
backButtonItem.imageInsets = UIEdgeInsetsMake(45, 5, 45, 85);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
-(void) Back:(id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
In firstcontroller
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.translatesAutoresizingMaskIntoConstraints = false;
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationItem.title = #"Home";
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor whiteColor]};
[super viewWillAppear:animated];
}
and write code in SecondView controller
- (void)viewDidLoad
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
}
ViewController.h file:
- (void)showForViewController:(UIViewController*)controller;
ViewController.m file:
- (void)showForViewController:(UIViewController *)controller {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
[self setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}
else
{
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
}
[controller.navigationController presentViewController:self animated:NO completion:nil];
}
I'm using this code for present ViewController with clear background (to see previous controller).

Replace custom back button with default

There is a lot of questions about how to replace the default back button with a custom back button, but none that I know of about how to replace a custom back button with the default.
I have a web view that when [self.webView canGoBack] == YES, a custom back button appears. But after you go back all the way, that custom back button is still there, rather than the default. Is there something I can do to replace my custom back button with the default when [self.webView canGoBack] == NO?
Here is my relevant code:
#interface MerchViewController () <UIWebViewDelegate>
#property UIWebView *webView;
#end
#implementation MerchViewController
- (instancetype)init
{
self = [super init];
if (self) {
self.navigationItem.title = #"Merchandise";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] init];
webView.scalesPageToFit = YES;
self.view = webView;
self.webView = webView;
webView.delegate = self;
[self setURL];
}
- (void)updateBackButton {
if ([self.webView canGoBack]) {
{
[self.navigationItem setHidesBackButton:YES animated:NO];
//UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"backTickets"] style:UIBarButtonItemStylePlain target:self action:#selector(backWasClicked:)];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] backButtonWith:#"Back" tintColor:[UIColor orangeColor] target:self andAction:#selector(backWasClicked:)];
backItem.tintColor = [UIColor orangeColor];
[self.navigationItem setLeftBarButtonItem:backItem animated:NO];
}
}
else {
/*
[self.navigationItem setHidesBackButton:YES animated:NO];
//UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"backTickets"] style:UIBarButtonItemStylePlain target:self action:#selector(backWasClicked:)];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] backButtonWith:#"Fan Zone" tintColor:[UIColor orangeColor] target:self andAction:#selector(openMenu:)];
backItem.tintColor = [UIColor orangeColor];
[self.navigationItem setLeftBarButtonItem:backItem animated:NO];
*/
}
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[self updateBackButton];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self updateBackButton];
[_spinner stopAnimating];
}
- (void)backWasClicked:(id)sender {
if ([self.webView canGoBack]) {
[self.webView goBack];
}
}
- (void)setURL
{
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.lawlorscustom.com/omaha-lancers-hockey"]];
NSLog(#"loadRequest: %#", req);
[(UIWebView *)self.view loadRequest:req];
}
#end
The "else" portion in "updateBackButton" is commented out because if I don't comment it out, when the view first loads there are two back buttons overlapping.
After struggling for a while, the answer was to do:
[self.navigationItem setHidesBackButton:NO animated:NO];
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;

Custom Navigation Transitions on iOS 7, how to manage the keyboard?

TabBarController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
PlaylistViewController *playlistViewController = [[PlaylistViewController alloc] init];
UIViewController *otherViewController = [[UIViewController alloc] init];
UINavigationController *playlistNavigationController = [[UINavigationController alloc] initWithRootViewController:playlistViewController];
playlistNavigationController.delegate = self;
self.viewControllers = #[playlistNavigationController, otherViewController];
playlistNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:kTabBarTagPlaylist];
playlistNavigationController.tabBarItem.title = #"Playlist";
otherViewController.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:kTabBarTagOther];
playlistNavigationController.navigationBar.tintColor = [UIColor redColor];
}
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
if (operation == UINavigationControllerOperationPush) return [[FadeTransition alloc] init];
else if (operation == UINavigationControllerOperationPop) return [[SlideTransition alloc] init];
return nil;
}
PlaylistViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
UIBarButtonItem *storeBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Store"
style:UIBarButtonItemStylePlain
target:self
action:#selector(test)];
self.navigationItem.leftBarButtonItem = storeBarButtonItem;
UIBarButtonItem *currentlyPlayingButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Now playing"
style:UIBarButtonItemStylePlain
target:self
action:#selector(test)];
self.navigationItem.rightBarButtonItem = currentlyPlayingButtonItem;
self.navigationItem.title = #"Playlist";
self.playlistTableViewController = [[PlaylistTableViewController alloc] initWithStyle:UITableViewStylePlain];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
searchBar.placeholder = #"Search";
searchBar.delegate = self;
self.playlistTableViewController.tableView.tableHeaderView = searchBar;
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.searchController.delegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
[self addChildViewController:self.playlistTableViewController];
[self.view addSubview:self.playlistTableViewController.view];
self.playlistTableViewController.view.frame = self.view.bounds;
self.playlistTableViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.playlistTableViewController didMoveToParentViewController:self];
}
FadeTransition.m
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
return 0.5;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
/* view controllers */
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
/* views */
UIView *containerView = [transitionContext containerView];
[containerView addSubview:fromVC.view];
[containerView addSubview:toVC.view];
/* settings */
toVC.view.alpha = 0.0f; /* not visible at start */
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0
options:UIViewAnimationOptionTransitionNone
animations:^{
toVC.view.alpha = 1.0f; /* 100% visible at the end */
}
completion:^(BOOL finished) {
[fromVC.view removeFromSuperview];
[transitionContext completeTransition:YES];
}];
}
This is how it looks like:
When I touch one of the results, a new UIView gets pushed and animated by FadeTransition.
The keyboard automatically gets slided down, but I need to leave the keyboard opened (it should stay behind), how can I do it?

easier way to subview a UIImagePickerController? mines not working

When I run my code and launch the camera with the code below I get my custom overlayView along with the default camera buttons. The only problem is, now, I get a blank black box where my UIImagePicker once was. I am simply trying to create a camera using the default UIImagePicker controls and buttons and then add my own IBOutlet UILabel over top of the default imagePickerController so that my label is displayed along with all the default camera controls. I'm having a terrible time accomplishing this though. cheers!
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagePicker.cameraOverlayView.frame;
self.imagePicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
}
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
Try to use my code. It worked fine. May be you achieve what you want. I created a controller, and used it's view to set cameraOverlayView property. I didn't use nib files, I created everything programmatically.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.tabBarItem.image = [UIImage imageNamed:#"86-camera"];
self.cameraOverlayViewController = [[CameraOverlayViewController alloc] init];
self.cameraOverlayViewController.picker = picker;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.toolbarHidden = YES;
picker.cameraOverlayView = self.cameraOverlayViewController.view;
picker.delegate = self.cameraOverlayViewController;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
This is a code for custom CameraOverlayViewController:
Interface file:
#import <UIKit/UIKit.h>
#interface CameraOverlayViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (nonatomic, strong) UIImagePickerController *picker;
#end
Implementation file:
#import "CameraOverlayViewController.h"
#import "BButton.h"
#import "AnalyseViewController.h"
#import "Tree.h"
#interface CameraOverlayViewController ()
{
}
#end
#implementation CameraOverlayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;
}
return self;
}
- (void)loadView
{
[super loadView];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bottom - 150, 320, 150)];
bottomView.backgroundColor = [UIColor blackColor];
BButton *button = [[BButton alloc] initWithFrame:CGRectMake(50, 25, 220, 50) type:BButtonTypePrimary];
[button setTitle:#"Сфотографировать" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[bottomView addSubview:button];
[self.view addSubview:bottomView];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
topView.backgroundColor = [UIColor clearColor];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 310, 60)];
infoLabel.backgroundColor = [UIColor clearColor];
infoLabel.font = [UIFont fontWithName:#"Georgia" size:18];
infoLabel.textColor = [UIColor whiteColor];
infoLabel.textAlignment = NSTextAlignmentCenter;
infoLabel.numberOfLines = 0;
infoLabel.text = #"Поместите лист дерева внутри рамки, чтобы\nсфотографировать его.";
[topView addSubview:infoLabel];
[self.view addSubview:topView];
UIView *bordersView = [[UIView alloc] initWithFrame:CGRectMake(10, topView.bottom + 10, 300, 300)];
bordersView.layer.cornerRadius = 10;
bordersView.layer.borderColor = [UIColor whiteColor].CGColor;
bordersView.layer.borderWidth = 2;
bordersView.backgroundColor = [UIColor clearColor];
[self.view addSubview:bordersView];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
AnalyseViewController *analyseViewController = [[AnalyseViewController alloc] initWithNibName:nil bundle:nil];
analyseViewController.baseImage = image;
analyseViewController.treesArray = [Tree retrieveAllTrees];
UINavigationController *analyseNavController = [[UINavigationController alloc] initWithRootViewController:analyseViewController];
[AppDel.tabBarController presentViewController:analyseNavController animated:YES completion:nil];
}
#pragma mark - Other methods
- (void)buttonClicked:(id)sender
{
[self.picker takePicture];
}
#end
Delete unneeded classes like BButton yourself.
fixed it with this. I did some research on CGPoints & CGRect and come up with this solution. Not sure if it is the most elegant solution but it works and seems to make pretty good sense. - (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = CGRectMake(160,0,0,0);
self.imagePicker.cameraOverlayView = self.overlayView;
}

Resources