popover segue with no anchor, MKMapView - iphone

I'm trying to present a popover over a pin I added to a MKMapView. I added a UIViewController to my storyboard, and dragged a segue from the MKMapView in one view controller to the viewController I want to show in my popover and selected popover. I get the error:
Popover segue with no anchor
In IB, I see "Drag to select an anchor", but when I try dragging it anywhere within the first viewController that has the MKMapView in it, nothing gets selected. I'm not sure where to go from here and if popover's from a view that is created dynamically can be used to present a popover with Storyboards. I know I can do it in code, but then I have to copy and paste my setters in prepareForSegue:. Thoughts? Thanks.

You need to make a custom annotation view. This will look like a popover view but it is actually different. A great tutorial on this can be found here: http://www.raywenderlich.com/30001/overlay-images-and-overlay-views-with-mapkit-tutorial
Essentially, you need to go NEW->NEW FILE-> the first option on the top left for OBJECTIVE C CLASS-> Name it whatever you want, I recommend CustomAnnotationView, and make it part of NSObject (rather than the default UIViewController)->follow the instructions on the above listed tutorial. If that tutorial does not work for you then you can search "custom map annotation" and many others will pop up. Apple even has a couple good (though outdated) sample projects which due this, such as a weather app and a callouts app with callouts for three locations in San Francisco.

Related

ViewController for Second View - iOS 7

I'm a beginner to iOS development, so forgive me if this is really basic. It's probably answered somewhere, but I've looked for a long time, and I'm struggling.
I have a second View on my story board that I've successfully linked to the first view using a Navigation controller and stuff, and I'm able to navigate to it. I can also add actions/outlets from elements on my first view by Control-dragging to the .h file.
I have a label on my second view, and I want to be able to do the same: add actions and outlets from elements. But when I try Control-dragging, nothing happens. What am I doing wrong, and how do I fix it?
Hmm, well first of all welcome to Stack Overflow! And thanks for asking the question.
Let me know if I have this right - you have two view controllers to the right (linked with segues) of a navigation controller and currently you can navigate to the second from the first using a button at the top right? Then when on the second view controller there's a nav button at the top left with a little arrow by it? And this should take you back to the first. Is that right?
Now on the second view controller you want to create a button that performs an action, but when you right-click-drag (ctrl-drag) onto a .h or .m file nothing happens?
If that's the case I've seen a few reasons for that. You might try:
You need to make a button, a label can only recieve actions, not create them. Read this article on IBOutlet vs IBAction
Restart Xcode (I know, it's lame, but humor me)
Make sure you're dragging (if on the .h file) between "#interface" and "#end"
Make sure you're dragging (if on the .m file) between "#implementation" and "#end"
Do you have a custom view controller class for your second view? If so, select the second view controller in your storyboard and go to the identity inspector. Set the custom class to your custom view controller's class name. Now you will be able to control-drag IBOutlets and IBActions.

Scene Dock in Apple's Date Cell Example?

I am looking at Apple's Date Cell (Date Cell Link) example project and I have a question about the Scene Dock in MyTableViewController. How come there are items extra items in the scene (Like Picker and Done) that are next to First Responder, Exit, and My Table View Controller? How can this be done? Also, how is this helpful?
This image shows the Scene Dock that I am referring to. Don't mind the titles, I renamed the project.
This image shows the Scene Outline for MyTableViewController, where the Picker and Done Button are shown next to the My Table View Controller, First Responder, and Exit and not within My Table View Controller.
This image shows an expanded outline for My Table View Controller where the Picker object is found also. But not Done Button is nowhere to be found inside My Table View Controller.
This image shows the code to connect to Picker and Done Button There is nothing special to this.
When I delete UIDatePicker in the scene of the controller (not in the cell), the inline DatePicker still works.
I think this sample is meant to support iOS 6.1 or earlier, to reveal the UIDatePicker as an external slide-in view, so it needs to be in the controller for IBOutlet connection.
Hope this will help.
Normally, the MyTableViewController should not be of type UITableViewController but its superclass UIViewController. This is normally necessary because UITableViewController has by definition its main view property set to the table view. It is then difficult to place other views into this view.
With a UIViewController, however, you can add any number of views. This is necessary in this case to accommodate the button and picker. The table view controller functionality can still be achieved by manually adding the UITableViewDataSource and UITableViewDelegate protocols and overriding the appropriate methods.
However, Apple here shows that it is possible by placing the other views on the same level as the main view, the table view. This is admittedly quite confusing. I usually prefer adding non-standard views as subviews to the view of a plain UIViewController.
You can drag things like picker views from the library to the scene dock to add them there.
As to the utility of doing this, I have no idea what that would be.
In this case I think that the picker and done button are left over from the writers of the code experimenting with ideas and forgetting to delete them. To verify that just delete the picker view and done button and see if everything still works.

How to swipe out of table view controller (not the cells) - iPhone

I have a tab bar app. It has 5 tabs. I have the 3rd tab connected to a navigation controller that's connected to a table view controller. Simple enough, right?
Well, I recently decided to implement left/right swipe gestures as an optional way to navigate left and right to each tab in the tab bar controlled app. The gestures work great, except I don't have a way to implement the gestures on the 3rd tab (the one with the UITableView) because there's no implementation file associated with it.
And that's my question: How can I implement the gestures on the third tab so I can navigate AWAY from it by swiping?? I can swipe into that tab, but not out of it. I'm fairly new to iOS dev, and I really appreciate any help!
(Using ARC, Storyboard, & Xcode 4.5.2)
EDIT:
Here's a screenshot of how my Table View Controller is connected to my Tab Bar Controller:
SOLUTION:
The answer marked correct is indeed correct. It explained to me how to make a subclass of my UITableViewController. But I was also wondering how to implement my TableView programmatically... so after a bit of searching, this link pretty much shows exactly how to do that: Ruchi Raval's post on mobisoftinfotech. However, I ended up just following the steps in the link, and I ended up deleting my original UITableViewController because I had created a new one through the steps in the link and connected it to my NavigationController through the Storyboard (ctrl + drag).
Hope this helps anyone that had my same quesions!
To control gestures on a VC, you'll need your own subclass. Create a new objective-c object named like MyTableViewController. Xcode lets you specify a superclass when creating the files, use UITableViewController.
Xcode provides some template code in the new files -- leave that alone to begin with. In storyboard, I think the tab you're trying to fix has a navigation (vc) whose root vc is a UITableViewController.
Select that table vc and select the Identity inspector (upper right, third tab from the left). You should see a section called custom class. The current class is probably UITableViewController. Change that to MyTableViewController, or whatever you named the new class.
Build and run. Now you control that table vc. Back in it's implementation file, you can add your gesture code in viewDidLoad:.

Loading an external view controller, from a button click on another view controller

Im officially getting annoyed with objective-c and xcode now. Programming in PHP and Java is so much easier haha.
Anyway I could do with some help.
I have created a tab bar application with three tab items for the iPhone, on one of the items it loads a nib named mapView, this contains a button that I want to use to load up another nib named OverlayViewController.
Ive been following this tutorial this tutorial
to create a camera overlay. I understand how it works, but I don't understand how to run the view controller from a button or direct from the tab bar. I can only get the overlay to work if I load it like in the example on application launch in the app delegate. If I try and load it from the tab bar item I just get a grey screen, looks like the blank view controller is loaded and the code hasnt been run to show the overlay.
If anyone can suggest how I would go about loading the overlay from the button click, or even direct from the tab bar item I would be really grateful.
Thanks Alex
p.s. Heres the link to the project if you wish to view the files
#AlexApps I took a look through your project and have several pieces of feedback.
I think before you get too into trying to get the OverlayViewController working you should back up a bit and give some of the Apple docs a read, especially the View Controller Programming Guide. The Apple docs are for the most part well written and should help you gain a better understanding of views and view controllers than what is evident in your code.
Another suggestion is to grab some of the freely available source code from a book such as Beginning iPhone Programming which has a good example of how to lay out a tabBarController based app. I am sure there are other good samples out there that will show you how to organize your views and view controllers to load them into the different tabs.
I think that if you follow this advice that by the time you have restructured your app by what you learn you will have less problem doing what you are trying to do.
BTW, you may want to consider using a NavigationViewController for what you are trying to do with loading the OverlayViewController with a button press but take a few hours, slow down and do some focused reading. It will make a world of difference. Then if you have more specific questions, Stack Overflow (and Google) are your friends.
One last tip, you do not need to put IBOutlet in your instance variables AND in your properties, just one or the other, and really, you don't even need the instance variables at all anymore. I usually just use properties for everything.
I have done it with storyboard and the solution is to create a segue between the tab bar view controller and the view controller you want to load, then you have to put an identifier to that segue. Finally, in the method called when the button is pressed you have to put this:
[self performSegueWithIdentifier:#"segueId" sender:sender];
I have done it right now and it works perfect!
First import uiviewcontroller class in frist page like below:
#import "page2viewcontroller.h"
on button click event code below:
page2viewcontroller *page2 =[page2viewcontroller alloc] ;
[self presentModalViewController:page2 animated:NO];
[page2 release];
after back page2viewcontroller to page1viewcontroller same as like below:
#import "page1viewcontroller.h"
on backbutton click event code below:
page1viewcontroller *page1 =[page2viewcontroller alloc] ;
[self presentModalViewController:page1 animated:NO];
[page1 release];
That's all....!

UITabBarController Hide Show Bars with animation like the Photo APP

i'm having a real trouble with UITabBarController. I have a simple foto app, and I'm trying to simulate almost the same behaviour as the PhotoApp from the Iphone
the main view controler is the tabbar itself, i also have a NavBar and a status bar on top.
What i want is on tap to hide the bars (not with timer, just on tap).
The photo is actually an UIScroll view that zooms the photo or makes it again 1:1. that part already works,
I've tried before pushing the view to the navbar to set the hidesBottomBarWhenPushed and well it works, but i can't set a custom animation, and that's not the real problem , I can't show again the bars, they dissapear and i don't know how to reshow them, i'm sure i'm probably missing someting very obvious, but as my experience in obj C is little like half a year part time, i thought i asked here as stackoverflow seems to get the answers :)
Something to investigate: the Three20 project: http://github.com/facebook/three20 - it includes a completely clone of the photo-browsing app in component form.
But without Three20, you can't do this with a stock UINavigationController, because the UIViewController that you're using is a subview of the UINavigationController. You need to make a sibling view on another layer. To do this, make a parent UIViewController which has two subviews: your photo, and a UIToolbar. You can hide and display the UIToolbar by setting it's hidden property, and make sure it's above the photo view with [parent.view bringSubviewToFront:toolbarController] (where parent is the main UIViewController that contains both the photo view and the UIToolbar)