Sorry I previously posted a question here, but The answers I got didn't work (probably my fault).
Basically, I want to stop a UIPopover from dismissing automatically. I got to this piece of code:
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
which I put in, but it doesn't seem to have any effect. Is there anything else I should add?
am I putting it in the right place (I was putting it in the vc.m of the view that has the popover within it)?
Thanks Very Much,
Luke
Check to make sure the UIPopover delegate is set. You can do this in code by setting the popover instance variable:
aPopover.delegate = self;
Related
Problem
I am having a rather big issue with the iOS7 keyboard appearance. I have a Searchbar on a UIViewController with TableView Delegation/Data Source setup (I am using the self.searchDisplayController delegates as well). I segue from this scene to a prototype tableview to show the results.
Here is the issue:
On first load I can see the keyboard being displayed when I tap into the text field of the UISearchBar. I can type and perform a search with the results being shown in the next scene.
I've added NSNotifications to view the keyboard properties in local methods keyboardWillShow and keyboardWasShown. I can see on the first scene appearance (after the view is completely loaded):
I segue to the result tableview at this point and when I navigate back and touch the text field, my keyboard shows up either fully or partially off-screen:
When I look at the keyboardWillShow notification at this point I can see that my keyboard values are incorrect:
I've researched and tried many possibilities including:
Added the following to my main view controller:
-(BOOL)canResignFirstResponder
{
return YES;
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
Configured the following in my view did load
self.searchDisplayController.searchBar.spellCheckingType = UITextSpellCheckingTypeNo;
self.searchDisplayController.searchBar.autocapitalizationType= UITextAutocapitalizationTypeNone;
self.searchDisplayController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchDisplayController.searchBar.keyboardType = UIKeyboardTypeDefault;
Put in standard stubs for:
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
I've noticed that if I choose a Partial Curl as my segue mode, the keyboard remains accessible when I roll back to the main view controller (but then it was never fully off screen in that case). However if I move from the results tableview to a detail scene and then navigate back to the main view controller, the keyboard appears off-screen again.
Question
Is there a method I can use to intercept the misplaced keyboard so that it displays in the default location?
NB: Along these lines, I have created a NSDictionary property to hold the initial userInfo values with the correct keyboard placement. I am not sure how to reassign these values to get the keyboard to return to it's original placement.
BTW - This seems a bit of a hack to get the keyboard fixed due to a bug in IB, is there some other way that I can try to remedy the situation?
Thanks in advance for any feedback!
Solution
This was such an obscure issue that I'm sharing the solution to save the next person some effort. Like most programming issues, it turns out this one was self-inflicted. In my original iteration of this project I had turned off rotational support as I am learning auto-layout and I wanted to ease into the transition from Springs and Struts. Somehow between the start of the project and the code release I ended up with this bit of code in the Main Scenes' View Controller.
//BAD
- (NSUInteger) supportedInterfaceOrientations
{
return !UIInterfaceOrientationPortraitUpsideDown;
}
instead of returning a valid enumeration like...
//OK
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
I've been working with iCarousel for about a week now, and I've had great success with outside testing. Now, I'm trying to put it into my app and it won't display the views. I was using UIViews to be displayed originally, which was working fine in my test programs, but due to sheer frustration im going as basic as possible and have literally just copied everythinng over from the examples. I connected the delegate and datasource, I called reloadData, ive done everything i could possibly find to fix this and it's not getting fixed. here's some code implementing the actual icarousel:
- (IBAction)coverflowPressed:(id)sender {
self.carousel = [[iCarouselExampleViewController alloc]
initWithNibName:#"iCarouselExampleViewController" bundle:nil];
[self presentViewController:self.carousel animated:YES completion:nil];
}
The rest of the code is basically copied from an example that works outside my app. As i mentioned, i DID connect the delegate and dataSource. It displays the background just fine, but it's like the carousel is empty; it has no items in it, and yes, there ARE items in it. any ideas for me?
EDIT
Maybe i connected the delegate and datasource wrong. could somebody maybe explain how to do that from an app thats already halfway through production?
Breakpoints prove that it's never reaching carousel-specific functions, like viewForItemAtIndex or even awakeFromNib. viewDidLoad is called, so i set the delegate and datasource in there. Originally they were set in the nib but i changed it to programmatically. anyways heres my viewdidload method:
- (void)viewDidLoad {
[super viewDidLoad];
self.carousel.delegate = self;
self.carousel.dataSource = self;
//configure carousel
_carousel.type = iCarouselTypeCoverFlow2;
}
it reaches the end of this function but it never goes any farther with it...
I'm presenting an EKEventEditViewController that I need for inserting an event into the calendar. All is fine, but how do I dismiss programmatically the keyboard when I go picking a date?
I know this is an old post but still didn't answered.I have been in this situation.So,like to share how to do it.
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d {
}
Inside this method you can put [textView resignFirstResponder].This will dismiss keyword while changing date.If you want to dismiss it at the beginning ..just use [textView resignFirstResponder] before calling calendar method .
Hope this will help others.
this is also a nice answer by kirby,you can try this too.
[self.view endEditing:YES];
Courtesy:-https://stackoverflow.com/a/3705527/1865424
The back button on a navigation controller is sometimes not appearing. Note that sometimes it does, so there is probably something else going on in som code elsewhere, but I have tried to debug this in every way I can think, and nothing seems to work.
The code for pushing the view controller is as follows (pretty standard):
CommentsTableViewController *vc = [[[CommentsTableViewController alloc] init] autorelease];
vc.puzzleID = self.puzzleModel.puzzleID;
[self.navigationController pushViewController:vc animated:YES];
To debug this problem, I have put the following code in the CommentsTableViewController in viewWillAppear and viewDidAppear (except I only register as an observer once):
self.navigationItem.hidesBackButton = NO;
[self.navigationItem addObserver:self forKeyPath:#"backBarButtonItem" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
self.navigationItem.backBarButtonItem.title = #"Tactic";
NSArray *viewControllerArray = [self.navigationController viewControllers];
int parentViewControllerIndex = [viewControllerArray count] - 2;
[[viewControllerArray objectAtIndex:parentViewControllerIndex] setTitle:#"Tactic"];
None of this seems to help. Putting breakpoints in, it seems like the view controller above me in the hierarchy has a title (#"Tactic") and hidesBackButton is already NO. The backBarButtonItem property is nil and is always nil, though I think this is expected behavior even when you do have a backBarButtonItem?
EDIT: In the parent controller, I am setting hidesBackBackButton to YES at first, and then later (before I push on the next controller), setting it back to NO. When I remove these lines, the new view controller has a back button. Why would the navigation item of one view controller affect the navigation item of the next?
Any suggestions or ideas are welcome. Thanks a lot.
Perhaps you might solve the problem debugging it better.You assumed that the button that leads you back is this:
self.navigationItem.backBarButtonItem.title = #"Tactic";
But that's nil, if you want to find that button look in the navigation controller's navigation bar:
NSLog(#"%#",self.navigationController.navigationBar.topItem);
I don't see a reason why your code isn't working, and you also don't need to do this:
self.navigationItem.hidesBackButton = NO;
Try this instead:
self.navigationController.navigationBar.topItem.hidesBackButton = NO;
Anyway this works for me even if I don't set it to NO.
If this doesn't solve the problem it should help at least debugging it, and if you still have that problem post in the comments, and say what does that NSLog() print.
Ok. I've worked it out. I have no idea why this makes a difference, but it does.
In the same run loop where I was calling hidesBackButton, I was also calling:
[self.view addSubview:self.chessBoardViewController.view];
This seemed to be the line that was screwing up the navigationBar somehow. If I remove this line, it works perfectly. So the solution I found was replacing this line with:
[self.view performSelector:#selector(addSubview:) withObject:self.chessBoardViewController.view afterDelay:0];
I dont' know why this worked, so if anyone has any insights on what might be happening, please comment.
In a project I'm writing I get this error when I present a new view controller:
Attempt to present.... while a presentation is in progress!
I think it happens because I first present a new view controller, and then in that view I present another view controller.
- (void)loadLabelSettings {
LabelSettingsViewController *labelSettings =
[[LabelSettingsViewController alloc] init];
labelSettings.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:labelSettings animated:YES completion:nil];
}
The program doesn't crash or anything it runs just fine, and there is no errors or warnings in my code. So my question is: Is it something I should be concerned with and if yes how do I solve it?
Thanks in advance :)
It is, like you said, probably caused by presenting two view controllers at the same time. Wait with presenting the second view controller until the first one has been fully presented. A good location would be to do this in viewDidAppear.
In my case, I connected a UIViewControllers UIButton with a second UIViewController by a UIStoryboardSegue. Inside my code a called it a second time programmatically. So pressing the UIButton caused presenting the specified view two times.
I figured out my problem, as Scott wrote it was because I was presenting 2 view controllers at the same time. It happened because I had a button that had a UILongPressGestureRecognizer, that showed the new view controller. The problem was that when using a UILongPressGestureRecognizer, the method that is being called, is called twice. First when the long press is detected and when your finger is released from the screen. So the presentViewController method of the same view, was called twice. I fixed this by only reacting to the first detection. Here is the code :
- (void)loadButtonSettings:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
}
}