Adding Subview Covers Up Navigation Bar in Navigation Controller - ios

I have a Navigation Controller that at times I need to present a subview for entering a password. The issue is that when I do this, it covers up the navigation bar, making going back in the hierarchy impossible to do. I use XIB for this, but it doesn't give me the option of resizing the UIView that adds on it.
if ([student isEqualToString:#"No"]) {
[self.navigationController.view addSubview:password];
[self.navigationController.view bringSubviewToFront:password];
}

Here are a few suggestions (assuming I understand your issue). Given that you are prompting for a password, I'm assuming you would want the user to either a) provide the password or b) cancel entering the password (not simply ignore it). If they do the latter, then the cancel button could be used to dismiss the password subview.
Suggestions:
Add a cancel button to your subview to dismiss the subview
Use a UIAlertView to present a modal dialog to capture the password with cancel button (see below)
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Password" message:#"Enter your password:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; // masks pwd text
If you're set on your current approach then define the subview similar to the following so that it is offset from the nav bar (or use constraints)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 200, tableView.frame.size.width, 100)];

It'd be helpful if you could provide a screenshot of what you're seeing and an image of the interface design you're trying to build.
The code above looks a little weird. Using addSubview: to add this type of view to your navigationController will likely have unintended consequences.
I would recommend either:
Building your password-entry UI in a new UIViewController subclass and using pushViewController:animated: to add this new viewController to the view hierarchy.
or
Use an alertView to capture the password entry, by either using the system UIAlertView or by building a custom alertView using a UIWindow.
Let me know if you need further explanation / clarification.

Related

iOS 7 UIDatePicker in UIAlertView customisation

Guys I was adding UIDatePicker to UIAlertView like this
It was fine with iOS 6 and below now in iOS 7 it comes like this
Any ideas why this happens? Is there a better way of doing this?.Any help is appreciated.
You can change accessoryView to any own customContentView in a standard alert view in iOS7
[alertView setValue:customContentView forKey:#"accessoryView"];
Note that you must call this before [alertView show].
Simplest illustrating example:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"TEST" message:#"subview" delegate:nil cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
v.backgroundColor = [UIColor yellowColor];
[av setValue:v forKey:#"accessoryView"];
[av show];
Exactly in the same way you can add your DatePicker.
This is my component to support addSubview in AlertView.
CXAlertView - Custom alert-view which allow you to add view as main content.
On iOS7, you should use the new custom modal transition support in UIKit using UIModalPresentationCustom and transitioningDelegate.
Using these, you can create a view similar to that of an alert view, but custom, where you could add a date picker.
More information here:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewControllerTransitioningDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intf/UIViewControllerTransitioningDelegate
There is no fix for this. Adding subviews to a UIAlertView was never supported and in iOS 7 this lead to subviews not showing. Some workarounds have been posted on the Apple Developer Forums, but they could easily break in a future release.
I suggest file a bug report. Many others (including myself) have done this, and the more requests Apple gets for it, the higher its priority becomes.
EDIT: I have written a UIAlertView clone that does allow for adding subviews: SDCAlertView.
It is not supported and I dont belive they 'fix this' .. roll your own alert view or use a open source alternative. see also UIAlertView addSubview in iOS7

Resign First Responder UITextView. Temporary UINavigationBar?

I am writing an application where I let the user edit some content in a text view, and I want to add a dismiss button, to let the user save there edits, without hacking around to dismiss the keyboard.
I am familiar with dismissing the keyboard programmatically and everything. The only real problem I have now, is a design problem. I want to let the user click a button just like in the notes app, but I don't have a UINavigationBar.
Is it possible to create a temporary Navigation bar and assign it a "done" button?
I am going to implement this in a custom UIView, so it should be controller independent. What I mean is I don't know if there is a UInavigationBar present in the current controller. So that must be dealt with dealt with before adding the temporary one.
Any help is appreciated.
Something like this would work nicely for what you're describing:
In viewDidLoad:
UIToolbar *inputToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneButtonTapped)];
[inputToolbar setItems:[NSArray arrayWithObject:doneButton]];
self.theTextView.inputAccessoryView = inputToolbar;
In doneButtonTapped
[self.view endEditing:YES];

Custom NavigationBar

I have a Navigation Controller as the root of my app and I am using the appearance proxy to customise the look on iOS 5, but for iOS 4 I was hoping to use a category to override drawRect:, this was fine, except that all the Navigation bars were affected as you would expect from a category.
I don't want to tamper with the "system" popups, such as the Mail composer, or the SMS composer, I want their bars to stay blue and system-like.
I Tried to create my own UINavigationController with it's xib and change the class of the NavigationBar to my custom sub lass of UINavigationBar. But the results are not taking affect at all on screen.
I am aware of the following post but couldn't get any solutions to run as expected.
How to subclass UINavigationBar for a UINavigationController programmatically?
My first attempt which does work but uses an undocumented setNavigationBar: method:
_myNavigationController = [[UINavigationController alloc] initWithRootViewController:someVC];
if([[BT_NavigationController class] respondsToSelector:#selector(appearance)]){
// some iOS 5 magic in here !
[_myNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"topbar.png"];
}else{
// Probably looking at app store refusal
CustomBar * bar = [[CustomBar alloc] init];
// [_myNavigationController setNavigationBar: bar];
[bar release];
}
[parentView presentModalViewController:_myNavigationController animated:YES];
To avoid that I created a UINavigationController, which I also had a xib for, reassigning the class of the navigation bar to my custom class, but placing breakpoints in drawRect: method, I can see that this isn't being called.
Why would that be, it seems that my code is not loading the nib, and therefore not realising the nab bar should be my custom class and not the UINavigationBar.
Any tips would be helpful, thanks.
If your modification is just about adding an image, you can simply insert it from the view controllers you want to customize:
UIImageView *bgImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"topbar.png"]] autorelease];
[self.navigationController.navigationBar addSubview:bgImageView];
You have to tweak a little based on what other elements you have in your UINavigationBar for your UIImageView to be at the lowest index of the subviews but still above the background. Worked for us.
Good luck.

MonoTouch for iPad: How to show a popup dialog?

I just started learning developing an application (primarily) for iPad using MonoTouch. Maybe because of my many years experience in C# world, it makes my switch very difficult, and I feel stupid sometimes. This is very simple thing in C#, but it make me scratch my head...
Popup dialog?
For iPhone, you rarely have this requirement, because whatever you show will occupy the whole screen, so you just create a controller for each popup.
For iPad, I have much more space, and I don't want the whole screen to be occupied with a few controls (e.g. login screen). That's why I want to show it as a popup. I have seen this in other iPad apps.
From what I learned, I need to use UIAlertView or UIActionSheet to do this. But what I don't understand is that, as shown by all the examples I have read, you have to create all the controls from the code.
What I would like to do is to create the UI using IB, and plug it into UIActionSheet. Is it possible? How do I do it?
If this is an iPad-only application, you will want to use a UIPopoverController. This is a popup "window" that contains a view and is linked to an area on the screen, such as a toolbar button or a rectangle (such as the Frame of a UIButton).
To use this, create a new instance of UIPopoverController, using the constructor that accepts a UIViewController and pass the view that you want to show.
Due to garbage collection considerations, make sure that you store the UIPopoverController in a class-level property.
You will probably also want to clean up this property when the popover is closed. To support this, we subclassed the UIPopoverController, added an event that can be hooked by the caller, then overrode the Dismiss method and fire the hooked event, if any, in the overridden method.
Once you instantiate the popover, you will want to show it. You can do this through one of the PresentFromxxx methods. If you are presenting this from a button (not toolbar) you can call PresentFromRect using the button's frame as the rectangle.
The view that is presented can control its size by setting the ContentSizeForViewInPopover property in its ViewDidLoad method.
You can't edit a UIActionSheet or UIAlertView from Interface Builder.
What you can do is create a view in Interface Builder and display it modally over top of your other views, however it sounds like you don't want to occupy the entire screen and this is what would happen. Here is an example of a modal view controller: http://pastebin.com/h221BQdK
I think you should just follow the examples you mention and create a UIAlertView from code, maybe put it a static utility class. I created a MessageBox class to be more like windows, but you can also put text boxes on there for login. Look at the login box on the app store, it is a decent example of what it would look like.
Create a viewcontroller named extraviewcontroller set its height width to 300 * 215 .
and write the code below
inviewdidload
pickerviewTitle = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, 383, 250)];
pickerviewTitle.delegate = self;
pickerviewTitle.tag = 0;
pickerviewTitle.showsSelectionIndicator = YES;
controller = [self.storyboard instantiateViewControllerWithIdentifier:#"ExtraViewController"];
popovercontroller = [[UIPopoverController alloc] initWithContentViewController:controller];
popovercontroller.delegate = self;
then
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:#"Title" delegate:self cancelButtonTitle:#"Done" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet1.tag = 0;
actionSheet1.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet1 addSubview:pickerviewTitle];
[actionSheet1 setFrame:CGRectMake(0, 0, 600, 400)];
[controller.view addSubview:actionSheet1];
if ([popovercontroller isPopoverVisible]) {
[popovercontroller dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect convertedFrame = yourclickbutton.frame;
[popovercontroller presentPopoverFromRect:convertedFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}

ABNewPersonViewController in a subview

I am writing an iPad app that requires the user to enter names and addresses and would like to use ABNewPersonViewController as the interface. The documentation says that this view controller should only be used from within a navigation controller. Is there anyway I can use just the ABNewPersonViewController in a subview (with a navigation controller) without it taking over my whole screen? I assume I can do this easily enough in a popover but I would prefer to have it integrated into my interface... Thanks for any help you can provide!
Consider presenting your UINavigationViewController by presentModalViewController:animated: and change modalViewPresentationStyle to UIModalPresentationPageSheet.
See the reference : http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
Well, after much looking into this, it does not see that there is any way to use the address book UIs in a subview but they do work quite well in a popover view. However, this popover needs to be exactly 320x460 pixels or some other number with the same aspect ratio for the "add photo" to work correctly (otherwise the photo is stretched). In the popover's view controller viewDidLoad method I added:
self.picker = [[[ABNewPersonViewController alloc] init] autorelease];
self.picker.newPersonViewDelegate = self;
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.picker] autorelease];
self.navigationController.view.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:self.navigationController.view];
This seems to work fine. Let me know if you know of something better.

Resources