Custom popups in iOS using storyboard views or separate nibs - iphone

What is the most correct/efficient/up-to-date way to present a popup window in iOS?
A la TweetBot:
Methods I've used:
Presented a popup from a separate nib and used loadNibNamed
Presented a popup from the main storyboard with instantiateViewControllerWithIdentifier
Created/Presented a popup purely programmatically*
*I'd rather not use this method because my popup has a fairly complicated custom UI
Also once I get the scene loaded from any of the methods above I don't know how to connect the UI elements in the popup with outlets/actions (Protocols? Delegates?)
If you could point me in the right direction for the most correct way of creating/showing/using a popup that would be fantastic.
Let me know if i'm being too vague, I can add more detail.

EDITED:
Hm, Just saw your screenshot after entering my answer. Well to do that, you can use a the feature provided by UIAlertView. I am pretty sure that is how the TweetBot guys do it as well. This link here shows a blog article that will let you do what you need.
Unless you want to go crazy custom, there are couple of solution out there that let you accomplish it. Something like this
DONE EDIT
One thing you can use is the Segues. Assuming you are using StoryBoard and when you tap on a button and that brings in a pop up view, you can connect them through something like this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"ViewToBringIn"]) {
ViewController *vc = [segue destinationViewController];
vc.navigationItem.title = #"some title";
}
}
Another way of using Segues could be through the StoryBoard UI. Click on the view you want, and that will bring up something like the screenshot in the Connection Inspector:
However, if you are using a nib file, then you can still create them and push them into the view (according to the format you want) via code. Of course the design on the view is done through the Interface Builder.

Related

Connect action of a XIB loaded from a custom class to a storyboard

I'm trying to create a reusable component to display some photo collection.
The basic flow is the following :
First view : View. It contains my so called library, designed programmatically and loaded from storyboard by assigning a custom class
I take a photo in a modal view, openend from the 'take picture' button
Once the photo is saved on disk, I ask PhotoLib to create a new PhotoCell from the photo path
I would like my PhotoCell to be touch enabled so when I tap it, it opens the second view in a modal way, but from what I read I cannot do this from my PhotoCell or the UIImageView inside (not a controller).
So how can I do ? View is embedded in a NavigationController, even if not shown in the screenshots below.
Thank you !
If you create Photocell in photolib, then photolib should implementing delegate methods from photocell. But photolib itself is not rootviewcontroller, so it should declare delegate methods itself, and the containing view should implement it.
Basically you pass Photocell from itself to Photolib (which implements delegate method
-(void) openPhotoCell:(Photocell*)cell
{
[self.delegate openPhotocell:(Photocell*)cell];
}
, then it passes it to View, which in its turn opens it.
It may seem like pulling a tooth from an ear, but actually it's quite working and if you write good self-explanatory code, it's not a problem. I'm currently working on some big project with tens views and controllers and it works pretty good and nobody has problem with that.
If you have more layers, then maybe you should look into NSNotification.
Hope it helped, I'd be glad to explain more.
UPD:
Links:
about delegates in cocoa fundamentals guide
delegation pattern in wikipedia

iOS: Segues vs IBAction?

I am just starting to learn about iPhone development and there seems to be very little resources on using Story Boards.
I have two view controllers, ActionViewController and ActionDetailViewController. AVC list the actions that a user has committed whereas ADVC shows the details of that particular action.
AVC has a "+" button to add a new Action, while AVDC has a "Done" and "Cancel" button.
I really like using storyboards because they are a fantastic way to visualize the app. However, I find that using segues to transition between the two screens quickly becomes visually complicated.
Can someone enlighten me what's the "typical" way of doing this? Do I really have a new segue for each action?
I also tried using IBActions. However, at AVDC I am unable to transit back to AVC with
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
Any ideas/
What I would do is set up a single Segue going from the AVC ViewController to the ADVC. Then when you want to perform the segue call
[self performSegueWithIdentifier:#"nameOfSegueIdentifier" sender:self];
Then override the delegate method below to set up the ADVC
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
Note you can use
[segue destinationViewController]
to get a pointer to the ADVC so you can manipulate it before it is pushed to the screen.
Hope this helps

Xcode 4.2 & Storyboard, how to pass data between views? Existing code error

I'm trying to learn how to pass data between views. Say set a label in the second view from text entered into a text field on the first view. I basically have tried making a string in the second view and then when switching from the first view to the second I set a string in the second view. Then when the second view loads its sets the text of a label to the same string. I NSLog right before and after the transition, before its fine, but when the second view loads it string gets erased. I'm not sure why this isn't working. Here is my project: http://www.mediafire.com/?83s88z5d06hhqb5
Thanks!
-Shredder2794
From my book (http://www.apeth.com/iOSBook/ch19.html#_storyboards):
Before a segue is performed, the source view controller is sent prepareForSegue:sender:. The view controller can work out what segue is being triggered by examining the segue’s identifier and destinationViewController properties, and the sender is the interface object that was tapped to trigger to the segue (or, if performSegueWithIdentifier:sender: was called in code, whatever object was supplied as the sender: argument). This is the moment when the source view controller and the destination view controller meet; the source view controller can thus perform configurations on the destination view controller, hand it data, and so forth.
(Of course another solution is "don't use a storyboard". Then the first view controller creates the second and can hand it data then and there.)
The reverse problem is much trickier; look at the Utility Application template for an example of how to use the delegate pattern.
StoryBoards are ready made things where you can reduce a lot of code you write.So consider controller A & B on storyboard.
Now for passing data From A to B you can connect them with a segue name its identifier and then you can use delegate methods in A as:
//This method gets called before transition from A to B.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"THE IDENTIFIER YOU NAMED"])
{
id *objectOfController_B = [segue destinationViewController];.
objectOfController_B.lblTextDisplayOfA = //Something...
}
}
Now You can Explicitly transition it by using button in controller A.
- (IBAction)buttonPressed:(id)sender
{
[self performSegueWithIdentifier:#"THE IDENTIFIER YOU NAMED" sender:sender];
}
So I guess you can try experimenting on this and you will get it how and when transition occurs with segue.
Hope this helps.
There appear to be more than a few things to explain. I think working through a few tutorials will give you the answers you need. See http://www.raywenderlich.com/tutorials
i've asked more or less the same question a few weeks/month ago. there were some very good answers, especially the one from zoul, who built a demo project that will show you how to create a factory pattern application that will provide the views with the needed objects.
my question can be found here: iOS: Initialise object at start of application for all controllers to use and have a look at the answer from 'zoul'. it got me through this problem =)
good luck trying it out =)
sebastian
I spent "countless hours" my self trying to find a way to pass data and understand delegates with no comprehension and very little success. This video did something that all the other references I checked didn't do : keep it as simple as possible while clearly showing what was needed. Thank you so very much Mr Rob Smythe. http://www.youtube.com/watch?v=XZWT0IV8FrI
Have a look at this: http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html
Delegate pattern is a common way to achieve what you are trying to do.

iPhone: How to show pop-up windows and dismiss them

In my Universal App I have a long UITableView with custom cells..and for some cells I may need to show some long pop-up explanaiton about that cell when for instance user clicks a "i" label on the cell. In iPad popover view seems excellent choice for this, but don't know how can I implement this on iPhone, what are the possibilities? Also I want to spend as less time as possible when making it work for iPad- popover view. I want to re-use some of the code or logic i use on iPhone
Things came up to my mind;
-Show explaination in alert shild, but the current look and feel of alert shield is ugly can I customize it however I like and show wherever I line on screen and if I can make it scrollable;
-Or maybe I can make a uitextview to show on top, but then how will I dismiss it, I will need some buttons there..which sounds tricky.
-UIActionsheet with a uitextview on it, is reasonable here?
Also I found this code in S.O but dont know how to use this in my case;
newView.frame = CGRectMake(60, 140, 200, 200);
[parentView addSubview:newView];
Have a look at http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html. It's a Popover component for iPhone. I think it works best in your case. You can Google "iphone popover" for more options.
We built an open source library for iPad-like popovers on iPhone allowing you to customise the look and feel of the popovers and place any view or controller inside it.
Watch the project on Github and download it at http://www.50pixels.com/blog/labs/open-library-fppopover-ipad-like-popovers-for-iphone/
On dismissing it, see the following instructions:
Know when a new popover is displayed
- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController
shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController;
Use this delegate method to know when a new different popover is displayed. If you want to dismiss the old popover, and release it, send the dismiss message inside this method.
- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController
shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController
{
[visiblePopoverController dismissPopoverAnimated:YES];
[visiblePopoverController autorelease];
}
Know when the popover is dismissed
- (void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController;
Use this delegate method to know when the popover is dismissed. This could happen when the user taps outside the popover or when a dismiss message is sent by other actions.
Typically if you used a UIPopover on the iPad you use present a Modal view controller on the iPhone.
So if you create a subclass of UIViewController (e.g. called MyViewController), with the necessary subviews such as a UILabel.
MyViewController *infoViewController = [[MyViewController alloc] init];
//pass data to the new view controller, e.g.
//[infoViewController setInfoText:...];
[self presentModalViewController:infoViewController animated:YES];
[infoViewController release];

Help Menu iPhone

I have a design question/technical question about my iPhone app.
I have a pretty simple (read really really simple) single view application. And it does everything that I need it to do. However I find myself in need of a help view. And I really don't quite know what to do!
I have a simple helpButton() method in my main view controller, and I really just want to display a scrollview with a bunch of images that show what to do during the use of my app. However, should I make a new viewcontroller class? How do I call it from my method?
Really I was thinking of an unfortunately simple method, just putting a scrollview behind everything and hiding it. Then showing it when the IBAction is called. Horrible...
Sorry if this is elementary, I haven't needed to do anything more yet!
You can push a modalViewController. To do that just make a new viewController with the scrollview and associated data in it, then
MyViewController *myViewController = [[MyViewController alloc] init];
[self presentModalViewController:myViewController animated:YES];
Create an IBAction in your new viewController and a hooked up button to that action to dismiss the modalView (something like this:
IBAction done {
[self dismissModalViewControllerAnimated:YES];
}
A couple options:
1) Create a new UIView object, either programmatically, or even in your existing XIB file. Use the [self.view addSubview:view] method to display it.
2) Create a new UIViewController with its own XIB file. Use [self presentModalViewController:anaimated:] to display it.
Either way, you'll need to add something to the new view to dismiss it when you're done.