UIActivityViewController not dismissing - iphone

I'm trying to add a custom UIActivity to a UIActivityController. When I click on the item, it presents the view controller I want it to, but when I finish with that view controller, the original UIActivityViewController is still there. My question is, how and where do I dismiss the activity view controller? This is the code in my custom UIActivity.
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems{
self.activityTitle = #"Text Editor";
self.activityType = #"TextEdit";
self.activityImage = [UIImage imageNamed:#"Icon.png"];
if (activityItems) return YES;
else return NO;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems{
for (NSString *path in activityItems) {
if ([path lastPathComponent]) {
self.file = path;
}
}
}
- (UIViewController *)activityViewController{
ACTextEditController *actec = [[ACTextEditController alloc] initWithFile:_file];
return actec;
}
EDIT
I've tried doing this, and I know it is called because I tried logging something in it and it was called
- (void)activityDidFinish:(BOOL)completed{
if (completed) {
[self.activityViewController dismissViewControllerAnimated:YES completion:nil];
}
}
however, it's still there when the view controller dismisses. Why?

Here's a working example:
http://www.apeth.com/iOSBook/ch26.html#_activity_view
Notice that we end up by calling activityDidFinish:. That is what tears down the original interface. It may be that that is the step you are omitting. If not, just compare what you're doing with what I'm doing, since what I'm doing works (on iPhone).

Related

How to check whether I am in the rootview of that viewcontroller in tabbaritem?

I have an iPhone application in which I am testing in the applicationDidBecomeActive: that if the selected viewcontroller's rootview is there, then I want to call one webservice, otherwise not when I am coming from background to foreground I am taking the stack and checking it. But now even if I am in the rootview the webservice is not getting called. Can anybody help me on this?
Here is my code snippet:
- (void)applicationDidBecomeActive:(UIApplication *)application{
NSLog(#"applicationWilssnd");
if(tabBarController.selectedIndex==0)
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(#"%#",mycontrollers);
///if([mycontrollers objectAtIndex:0]!=)
///[[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO];
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
{
}
else
{
[pinvc merchantnews];
}
mycontrollers = nil;
tabBarController.selectedIndex = 0;
}
}
`here the merchantnews is not getting called.
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if([mycontrollers objectAtIndex:0]!=pinvc)
Instead of this, try this
PinBoardViewController *pinvc=(PinBoardViewController*)[[mycontrollers objectAtIndex:0]topViewController] ;
if(pinvc isKindOfClass:[PinBoardViewController class]){
// Do ur stuff
}

Segue crashing - debugger doesn't display any useful error

UPDATE:
Ok, I managed to log the exception:
[<TweetDetailViewController 0x685f9f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key toolbar.
I have a toolbar in the target controller view. Could that be causing the problem?
I have no idea what the heck is going on. I have not changed segues at all and they worked perfectly few minutes ago. I was changing some unrelated things in a detail view controller and now the app crashes during segue from the root to the view controller.
I am trying to debug this. Here is where the code crashes:
Step over:
Step over:
Step over:
Ok, here is the setter method which is being called in prepareForSegue:
- (void)setTweet:(Tweet *)newTweet
{
if (_tweet != newTweet) {
_tweet = newTweet;
}
}
I call a configuration method when entering the detail controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self configureView];
}
- (void)configureView
{
// Update the user interface for the tweet detail page
if (_tweet) {
self.tweetUserName.text = _tweet.userName;
self.tweetCreatedAt.text = _tweet.createdAt;
self.tweetText.contentInset = UIEdgeInsetsMake(-4,-8,0,0);
self.tweetText.text = _tweet.text;
if (_tweet.retweeted == YES) {
[self.retweetButton setTintColor:[UIColor grayColor]];
[self.retweetButton setEnabled:NO];
}
if (!_tweet.userProfileImage) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imageUrl = _tweet.userProfileImageUrl;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
dispatch_async(dispatch_get_main_queue(), ^{
self.tweetUserProfileImage.image = [UIImage imageWithData:data];
});
});
}
else {
self.tweetUserProfileImage.image = _tweet.userProfileImage;
}
}
}
Copied from comments, as an answer once the actual exception was revealed:
Most likely the TweetDetailViewController in your storyboard has some connection that links to an outlet called "toolbar" but the code for that class doesn't have a property with that name. That's the usual reason at least for that kind of error when a view controller is involved.
Try enabling control over the Zombie, to see if the debug gives you more details about the problem.
On edit scheme under the heading "Envirorment Variables" add NSZombieEnabled = YES
Please try and see if you have more details

iOS: How to access the `UIKeyboard`?

I want to get a pointer reference to UIKeyboard *keyboard to the keyboard on screen so that I can add a transparent subview to it, covering it completely, to achieve the effect of disabling the UIKeyboard without hiding it.
In doing this, can I assume that there's only one UIKeyboard on the screen at a time? I.e., is it a singleton? Where's the method [UIKeyboard sharedInstance]. Brownie points if you implement that method via a category. Or, even more brownie points if you convince me why it's a bad idea to assume only one keyboard and give me a better solution.
Try this:
// my func
- (void) findKeyboard {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIKeyboard.
UIView *foundKeyboard = nil;
for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
if ([[possibleKeyboard description] hasPrefix:#"<UIPeripheralHostView"]) {
possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
}
if ([[possibleKeyboard description] hasPrefix:#"<UIKeyboard"]) {
foundKeyboard = possibleKeyboard;
break;
}
}
}
How about using -[UIApplication beginIgnoringInteractionEvents]?
Also, another trick to get the view containing the keyboard is to initialize a dummy view with CGRectZero and set it as the inputAccessoryView of your UITextField or UITextView. Then, get its superview. Still, such shenanigans is private/undocumented, but I've heard of apps doing that and getting accepted anyhow. I mean, how else would Instagram be able to make their comment keyboard interactive (dismiss on swipe) like the Messages keyboard?
I found that developerdoug's answer wasn't working on iOS 7, but by modifying things slightly I managed to get access to what I needed. Here's the code I used:
-(UIView*)findKeyboard
{
UIView *keyboard = nil;
for (UIWindow* window in [UIApplication sharedApplication].windows)
{
for (UIView *possibleKeyboard in window.subviews)
{
if ([[possibleKeyboard description] hasPrefix:#"<UIPeripheralHostView"])
{
keyboard = possibleKeyboard;
break;
}
}
}
return keyboard;
}
From what I could make out, in iOS 7 the keyboard is composed of a UIPeripheralHostView containing two subviews: a UIKBInputBackdropView (which provides the blur effect on whatever's underneath the keyboard) and a UIKeyboardAutomatic (which provides the character keys). Manipulating the UIPeripheralHostView seems to be equivalent to manipulating the entire keyboard.
Discaimer: I have no idea whether Apple will accept an app that uses this technique, nor whether it will still work in future SDKs.
Be aware, Apple has made it clear that applications which modify private view hierarchies without explicit approval beforehand will be rejected. Take a look in the Apple Developer Forums for various developers' experience on the issue.
If you're just trying to disable the keyboard (prevent it from receiving touches), you might try adding a transparent UIView that is the full size of the screen for the current orientation. If you add it as a subview of the main window, it might work. Apple hasn't made any public method of disabling the keyboard that I'm aware of - you might want to use one of your support incidents with Apple, maybe they will let you in on the solution.
For an app I am currently developing I am using a really quick and easy method:
Add this in the header file:
// Add in interface
UIWindow * _window;
// Add as property
#property (strong, nonatomic) IBOutlet UIView * _keyboard;
Then add this code in the bottom of the keyboardWillShow function:
-(void) keyboardWillShow: (NSNotification *) notification {
.... // other keyboard will show code //
_window = [UIApplication sharedApplication].windows.lastObject;
[NSTimer scheduledTimerWithTimeInterval:0.05
target:self
selector:#selector(allocateKeyboard)
userInfo:nil
repeats:NO];
}
This code look for when the keyboard is raised and then allocates the current window. I have then added a timer to allocate the keyboard as there were some issues when allocated immediately.
- (void)allocateKeyboard {
if (!_keyboard) {
if (_window.subviews.count) {
// The keyboard is always the 0th subview
_keyboard = _window.subviews[0];
}
}
}
We now have the keyboard allocated which gives you direct "access" to the keyboard as the question asks.
Hope this helps
Under iOS 8 it appears you have to jump down the chain more than in the past. The following works for me to get the keyboard, although with custom keyboards available and such I wouldn't rely on this working unless you're running in a controlled environment.
- (UIView *)findKeyboard {
for (UIWindow* window in [UIApplication sharedApplication].windows) {
UIView *inputSetContainer = [self viewWithPrefix:#"<UIInputSetContainerView" inView:window];
if (inputSetContainer) {
UIView *inputSetHost = [self viewWithPrefix:#"<UIInputSetHostView" inView:inputSetContainer];
if (inputSetHost) {
UIView *kbinputbackdrop = [self viewWithPrefix:#"<_UIKBCompatInput" inView:inputSetHost];
if (kbinputbackdrop) {
UIView *theKeyboard = [self viewWithPrefix:#"<UIKeyboard" inView:kbinputbackdrop];
return theKeyboard;
}
}
}
}
return nil;
}
- (UIView *)viewWithPrefix:(NSString *)prefix inView:(UIView *)view {
for (UIView *subview in view.subviews) {
if ([[subview description] hasPrefix:prefix]) {
return subview;
}
}
return nil;
}

hiding and displaying uitoolbar on same button click

I am trying to hide and display a UIView on BarButtonItem click. Priviously i also posted the question regarding same but didnt find any suitable answer. I created UIView manually in IB and just placed it in view so it must be shown as soon as view is loaded but i made it hidden in viewDidLoad method by writing
myvew.hidden = YES;
secondly, when i click BarButtonItem then i set
-(IBAction)mymethod
{
myview.hidden = NO;
}
so its diplaying view but when i again click on it it must hide.. how do i do it?
Put the following statement in your button action
myview.hidden = !myview.hidden ;
So your code must be like below.
-(IBAction)mymethod
{
myview.hidden = !myview.hidden ;
}
if (myview.hidden == YES)
{
myview.hidden = NO;
}
else
{
myview.hidden = YES;
}
Check if the view is already hidden and then show, and if not hidden then hide it.
You should do in this way
-(IBAction)mymethod
{
if( myview.hidden == NO ) myview.hidden = YES;
else myview.hidden = NO;
}

Screen corruption after dismissing modal UIImagePickerController subclass

I am having trouble dismissing a modal view controller containing a UIImagePickerController (ZBarScannerController). For some reason, after dismissing the controller after scanning a bar code with the iphone camera, the view controller always leaves a rectangle of stale graphical data over the same area as the ZBarScannerController's tool bar. The corrupt data is always a portion of whatever image the camera was seeing at the moment.
An image of the problem (corrupt area in red rectangle):
It is impossible to remove that rectangle of corrupt screen data except by backgrounding / killing the app. Also, if I specify NO when I dismiss the modal picker, the OS will remove the view controller while still displaying the controller on screen, causing crashes if I interact with any controls on the modal view. How can I go about fixing the problem?
Code for dismissing the controller:
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results =
[info objectForKey:ZBarReaderControllerResults];
for (ZBarSymbol *oSymbol in results) {
//process result
//Ensure that QR code is decoded
zbar_symbol_type_t type = oSymbol.type;
if (type == ZBAR_QRCODE) {
//Get Barcode Data
NSString *dataStr = oSymbol.data;
[self processCommand:dataStr];
}
}
//[reader dismissModalViewControllerAnimated:NO];
[[m_oReaderController parentViewController] dismissModalViewControllerAnimated:YES];
}
Code for making the controller:
- (void)onQRCameraActivate:(id)sender {
IPOProofAppDelegate *oAppDelegate = (IPOProofAppDelegate *) [[UIApplication sharedApplication] delegate];
if (m_oReaderController == nil) {
m_oReaderController = [[ZBarReaderViewController alloc] init];
m_oReaderController.readerDelegate = self;
ZBarImageScanner *oScanner = m_oReaderController.scanner;
[oScanner setSymbology:0 config:ZBAR_CFG_ENABLE to:0];
[oScanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ENABLE to:1];
}
[self.navigationController presentModalViewController:m_oReaderController animated:YES];
}