UIPopoverController not dismissing in xCode 5/ios7 - xcode4.5

Since upgrading to iOS 7 and xCode 5 my popovers are not dismissing when the user selects an item. They have to tap outside of the popover to get it to go away.
In the following the UITableViewController is foundPatientsViewController and I am creating the propover like this from my root view controller...
TodaysPatientsViewController *foundPatientsViewController =[[TodaysPatientsViewController alloc] init];
foundPatientsViewController.patientList = patientList;
foundPatientsViewController.delegate = self;
foundPatientsViewController.patientNameOnly = YES;
UIPopoverController *foundPatientsPopOver = [[UIPopoverController alloc] initWithContentViewController:foundPatientsViewController];
foundPatientsPopOver.delegate = self;
foundPatientsViewController.myPO = foundPatientsPopOver;
[foundPatientsPopOver presentPopoverFromBarButtonItem:findPatientButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[foundPatientsPopOver setPopoverContentSize:CGSizeMake(300, popOverHeight) animated:NO];
[foundPatientsViewController release];
In foundPatientsViewController I have...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[myPO dismissPopoverAnimated:YES];
[self.delegate patienSelectedForDisplay:self withPatientNumber:[patientNumbers objectAtIndex:indexPath.row] patientName:[patients objectAtIndex:indexPath.row]];
}
What has changed?
Thanks,
John

Related

How to set title for Navigation Bar

How to set the title on a root viewcontroller inside a navigation viewcontroller. Generically, the answer seems to be, "set self.title of some viewcontroller". but this only works for the viewcontrollers I am pushing to. On the initial viewcontroller, running self.title = #"my title"; or self.navigationController.navigationItem.title = #"my titles"; don't work.
Thinking that is needed to be set earlier on, I did this in app delegate:
MainMenuViewController *mainMenuViewController = [[MainMenuViewController alloc] initWithNibName:#"MainMenuViewController" bundle:nil];
mainMenuViewController.title = #"coding chal";
self.navController = [[UINavigationController alloc] initWithRootViewController:mainMenuViewController];
What must I do for the root viewcontroller to have a title?Thanks in advance
Setting the view controller's title does work. When you run into trouble, the best course is make yourself a minimal test example. Here's one. This is the only code in the app!
In the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [UIWindow new];
ViewController* vc = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
In the view controller:
- (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
self.title = #"Testing";
return self;
}
Result:
So you can see that it really does work. If it seems not to work in your app project, therefore, that must be because of other code somewhere.

UINavigationBar does not show on second ViewController on Apple TV

I have the following code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:#"ViewController"];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
UILabel* topBar = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
topBar.text = #"Custom Navigation";
[navigationController.navigationBar.topItem setTitleView:topBar];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
When the button is clicked, the following code is run;
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* second = [sb instantiateViewControllerWithIdentifier:#"second"];
[self.navigationController setNavigationBarHidden:NO];
[self.navigationController pushViewController:second animated:YES];
The navigation bar is always hidden on the second screen. I tried [self.navigationController setNavigationBarHidden:NO] and [self.navigationController.navigationBar setHidden:NO] but it does not work.
My code runs successfully on iPhone or iPad, but does not work on Apple TV.
What is the solution to show the navigation bar on the second screen?
Don't use UINavigationBar on Apple TV. UITabBar is more useful. If you make custom tab bar, implement UITabBarController to your interface and write fallowing code to the viewDidLoad method.
customView = [[[NSBundle mainBundle] loadNibNamed:#"CustomTopBar" owner:self options:nil] objectAtIndex:0];
[self.view addSubview: customView];

iOS 6.1 - How do I implement imagePickerControllerDidCancel for a non-modal UIImagePickerController

On iOS 6.1, I am displaying a UIImagePickerController non-modally in one tab of a UITabBar.
In my init:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
[self.view addSubview:self.picker.view];
I have implemented:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
return;
}
Since I never called:
[picker presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion];
I shouldn't need to call:
[picker dismissViewControllerAnimated:NO completion:nil];
But, when I press the Cancel button, the Cancel button is grayed out and the UIImagePickerController seems to lock up. Some of the controls work, like the image/video switch and the reverse camera button, but the button to take a picture is frozen.
If I go to a different tab and return to the Camera tab, the UIImagePickerController is reset and fine again. The only code executed in this case is viewWillAppear and viewDidAppear which shouldn't have anything relevant to this situation.
On iOS 7,nothing locks up when the Cancel button is pressed.
Since the UIImagePickerController is always displayed in the tab, I don't really have a need for a cancel button so how would I either:
Hide or disable the Cancel button
Implement imagePickerControllerDidCancel so things do not lock up
Implemented a Camera Overlay View and things work fine.
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
self.picker.showsCameraControls = NO;
UIView *clearView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
clearView.opaque = NO;
clearView.backgroundColor = [UIColor clearColor];
UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-self.tabBarController.tabBar.frame.size.height-55, self.view.frame.size.width, 55)];
toolBar.barStyle = UIBarStyleBlackOpaque;
NSArray *items=[NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:#selector(takePicture)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
nil];
[toolBar setItems:items];
UIView *overlayView = [[UIView alloc] initWithFrame:self.view.bounds];
[overlayView addSubview:clearView];
[overlayView addSubview:toolBar];
[self.picker setCameraOverlayView:overlayView];
[self.view addSubview:self.picker.view];
[[UIBarButtonItem alloc] ... action:#selector(takePicture)],
- (void)takePicture
{
[self.picker takePicture]; // triggers didFinishPickingMediaWithInfo
}
UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (image != nil)
{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
}

loading another tableview when a tablecell of one tableview is clicked returning error:"Program received signal SIGABRT"

I am creating an app in which there are two UIViews and in those UIViews I am loading Tableviews..
When I click a tablecell in one TableView then I am unable to redirect it to another TableView and getting error:Program received signal SIGABRT.But if I want to load a UIView when a tablecell is clicked it gets executed perfectly.I couldn't understand where Am I going wrong....
This is the code i'm writing
ViewController1:
#import ViewController2.h"
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ViewController2 *v2 = [ViewController alloc] initWithNibName:#"ViewController2" bundle:[NSBundle mainBundle]];
[self presentModalViewController:v2 animated:NO]; **//getting error at this line**
[v2 release];
}
ViewController2.h
#import"ViewController1.h"
- (void)viewDidLoad
{
[super viewDidLoad];
tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(10, 10, 320, 460)];
tableView1.delegate = self;
tableView1.dataSource = self;
[self.view addSubview:tableView1];
}
Couldn't understand what could be the possible cause of this error..
Maybe this is the bug
ViewController2 *v2 = [ViewController alloc] initWithNibName:#"ViewController2" bundle:[NSBundle mainBundle]];
You have allocated ViewController instead of ViewController2
Try this and it should work, I guess.
ViewController2 *v2 = [ViewController2 alloc] initWithNibName:#"ViewController2" bundle:[NSBundle mainBundle]];

navigation inside tabbar which is called modally from a didSelectRowAtIndexPath

I am creating an app as follows- when the app starts a tableview is displayed. I am creating this programmatically. On selecting a particular row i do a presentModalViewController to display my tabbar class which i created programmatically.
ViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ShowOptionInTab *showTabbar = [[ShowOptionInTab alloc] initWithNibName:#"ShowOptionInTab" bundle:nil];
UINavigationController *mynavController = [[UINavigationController alloc] initWithRootViewController:showTabbar];
[self presentModalViewController:mynavController animated:YES];
[showTabbar release];
}
ShowOptionsInTab.m class
#implementation ShowOptionInTab
-(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissTabbar:)];
self.navigationItem.rightBarButtonItem=doneButton;
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0, 0, 320, 460);
BuyerViewController *buyerController = [[BuyerViewController alloc] init ];
buyerController.navigationItem.title=#"Buyer";
buyerController.title=#"Buyer";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
SellerViewController *sellerController = [[SellerViewController alloc] init];
sellerController.navigationItem.title=#"Seller";
sellerController.title=#"Seller";
LenderViewController *lenderController = [[LenderViewController alloc] init];
lenderController.navigationItem.title=#"Lender";
lenderController.title=#"Lender";
tabbarController.viewControllers = [NSArray arrayWithObjects:buyerController,sellerController,lenderController, nil];
[self.view addSubview:tabbarController.view];
[sellerController release];
[buyerController release];
[lenderController release];
}
-(void)dismissTabbar:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
My ShowOptionsInTab class is a subclass of UIViewController
I have 3 tabs Buyer, Lender and Seller. Each tab has buttons which navigate to a different UIViewController page. Suppose i have 'ButtonA' and 'ButtonB' in my Buyer tab class. The problem i am facing is that i cannot navigate on the buttons present in Buyers tabs(or any other tabs). It doesnt push to the next class which 'ButtonA' should load. It also has a "Done" button on navigation bar which will dismiss the modal view and display my table view.
What am i doing wrong? if i add these tabs to localNavigationController object which i create in my ShowOptionsInTab.m class i get 2 Navigations Bars.
I got the solution. I made 3 local navigationController object and added each of my tabbar class as its rootviewController.

Resources