MonoTouch and UIPopoverController - ipad

I have a iPad app with the following code tied to a button's (bMyDocuments) TouchDown event handler:
UIPopoverController uipoc = new UIPopoverController(new Pop2());
uipoc.PopoverContentSize = new SizeF(200f, 300f);
uipoc.PresentFromRect (bMyDocuments.Frame, v, UIPopoverArrowDirection.Up, true);
Pop2 is a blank UIViewController with the default view (white background, no ui elements).
This code produces a popover from the button, and the size is correct. However the app hangs without any errors, and popover won't disappear when clicking outside of it.
How can I initialize UIPopoverController correctly? Sample code?
thanks,
pom

Chances are that the garbage collector is eating up your UIPopoverController. Try declaring your UIPopovercontroller as a class variable instead of inside your TouchDown event and see how that goes.
Cheers,
ChrisNTR

Related

The handler of a UIAlertAction is a bit too late - how can I make it immediate?

I am trying (...) to add a sound effect to the buttons added to a UIAlertController. I fire a sound effect in the handler, but this actually is a bit too late. The sound fires like 0.5 seconds too late. I want the sound to fire as soon as the alert is about to dismiss, not after it has dismissed. With UIAlertView this was possible to handle using alertWillDismiss... rather than alertDidDismiss.
Did I miss something?
No, you didn't miss anything. The functionality you're looking for is not provided by UIAlertController. Consider providing your own presented view controller, over which you'll have the kind of fine control you're after.
I used Patrick Goley's suggestion, namely to subclass UIAlertController and override viewWillDisappear. Worked great for me.
//
// ImmediateClickAlertController.swift
//
// This subclass of UIAlertController plays a click immediately whenever it is dismissed (i.e. when a button is tapped).
// This fixes an issue when trying to play a click in an attached UIAlertAction, which does not happen until after its view disappears.
import AudioToolbox
class ImmediateClickAlertController: UIAlertController {
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
// play a click
let pressKeySystemSoundID: SystemSoundID = 1104
AudioServicesPlaySystemSound(pressKeySystemSoundID)
}
}
A bit of a hackery, but perhaps you could:
Try and grab a reference to the alert's button (by traversing the -admittedly private- view hierarchy tree), and
Use KVO to detect any changes to its selected and/or highlighted properties (my own experience is that selected is not reliably observable, while highlighted is).
...but all of this is quite fragile, not elegant, maight break in a future release of the OS and/or get you rejected from the app store...?
So you're best option (even if the most laborious) is to roll your own modal view controller:
Apple's documentation on presenting modal view controllers.
Demo project I made following the above docs (a custom "UIAlertController look-alike" with an embedded UIActivityIndicator - for use during long, asynchronous processes):

SIGABRT on every touch click, inconsistent iPad iOS

Let Say there was a working iPad app.
It has a TextField and a small button (arrow) at the end of the TextField. When ever the the small arrow is click, it should display the suggested options.(as UiPopOver)
The new requirement was , not only when the arrow button is clicked, even when the Textfield is touched, the popover should be shown over.
Method to show() in arrow button touchUpside event:
UIPopoverController activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[activityPopover presentPopoverFromBarButtonItem:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Method to hide():
[activityPopover dismissPopoverAnimated:YES];
What I did was very simple.
Added gestureevent to the text field and any single tap over it will trigger the arrow button click.
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
but after adding the above piece of code, my app started crashing randomly.. I could not trace the pattern. I tried setting break point, but could not find anything. It just shows the interrupt SIGABRT and crashes. no log is written.
commenting the above code, it works fine.
I have no clue how to trace the issue.
Any help please?
I got similar situation in my case, because the button event got triggered two times, when touched over the button. Probably, both SingleTap gesture and the button tap event are triggered at same time, and try to disable UserIneraction over the button, and call the method associated directly, instead of triggering button event! I am not sure about this is the root cause. Am not a pro too!
Good Luck!

Suppress darkening of main view when UIActionSheet displays

I have a UIActionSheet and when it displays it darkens the main view behind it, I am under the impression this is default behavior for an action sheet. My question is, how do I override this behavior to leave the main screen the same tint as it normally is? I'm assuming I do something like:
mainView.alpha = 1f;
Or something...I can't remember if alpha needs to be maxed or 0 to leave a screen with the same coloration/transparency. Anyways, if that is correct where should it happen? My action sheet is being called in place of a keyboard for a UITextField.
Thanks in advance.
You can't change this behavior. UIActionSheet is actually presenting a whole new view overtop of your view. It's this additional view that adds the tint. There is no API to change this.
Your best solution is to implement your own custom equivalent to UIActionSheet so it does exactly what you want.

clearButton not working in UITextEditField

This is one of those "it was working a while ago" troubleshooting efforts.
I'm working on the document preview view controller, in which is a scroll view, which itself contains subclasses of UIView that represent each document. I'm modeling this pretty closely to how Keynote handles its document preview, except I build my scroll view horizontally and with paging. But the standard user experience is present: Long press on a document icon causes all document icons to start jiggling, nab bar has + button and Edit button, etc.
The issue at hand is that when you tap on the name of a document, I hide all the others, move the one being edited front and center, build a new text edit field, add it as a subview atop the real name label, and set it as first responder; but the
[editNameTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
while correctly showing in the edit field is not taking any action when the user taps on the clear button.
I can't figure out what I may have done to cause this to not work -- it had been!
My first thought was that somehow my instance of this subclass is no longer the delegate for this text edit field. To try and confirm/deny that, I usurped a tap on the image view of the document preview to compare the delegate property to self, and it passes.
if (editNameTextField) {
NSLog(#"editNameTextField is still active");
if ([editNameTextField.delegate isEqual:self]) {
NSLog(#"we're still the delegate for the editNameTextField");
}
}
Editing the text within the edit field works fine. Pressing the Return/Done key correctly sends the delegate message textFieldShouldReturn:
While investigating this I implemented the delegate method textFieldShouldClear: just to write a log message if the method gets called (and return YES of course). It never gets called.
My next thought was that perhaps a subview had covered up the area where the clear button sits. So I implemented textFieldShouldBeginEditing: and used the opportunity to bring my the text field to the front. That didn't change anything either. I set a debugger breakpoint there to play a sound when it was called, and it got called, so I know my text edit field is frontmost.
I have only one troubleshooting strategy remaining: Go backwards through snap shots until it starts working again. Before doing that I thought I'd see if any of the more experienced folks out here have any suggestions of what to try next.
Where are you adding the textfield? As a subview of the scrollView? If you added the textfield and it is out of bounds of its parent view it won't receive any touches.
You can try and not call becomeFirstResponder and see if clicking it will show keyboard. Another possible error might be that the parent view of the UITextField has userInteractionEnabled = NO.
Without seeing more code I'm afraid I can not offer more solutions.

refresh button is not able to refresh UIView in monotouch iPad

i am new to iPad developer,
i have created two or three iPad application in objective c using Xcode 4.
but now i want to create iPad application using Monodeveloper tool in C# language...
in which, i want to insert Refresh button, on my NavigationBar,
here is my code snippet,
UIBarButtonItem button=new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
NavigationItem.LeftBarButtonItem=button;
i am able to see refresh button on my NavigationBar, but when i click it, my view doesn't refreshes.
how to refresh view, any idea ?
Thanx In Advance !!
Any Help Will be Appriciated.
You are initializing a UIBarButtonItem without a handler. So tapping the button does nothing.
Try this:
UIBarButtonItem button =
new UIBarButtonItem(UIBarButtonSystemItem.Refresh,
(s, e) => Console.WriteLine("Refresh!"));
You can also assign it after initialization:
UIBarButtonITem button = new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
button.Clicked += (s, e) => Console.WriteLine("Refresh!");
EDIT:
Inside the handler, you must implement your own "Refresh" code, depending on what it is you want to refresh. The UIBarButtonSystemItem enumeration merely defines the appearance of UIBarButtonItem buttons.

Resources