Maybe this is going to sound like a real weird thing I want to do, but let me explain my purpose.
I'm writing an app that links to Dropbox, and it displays the user all his folders and files. I want to write this in such a way that when the user taps a folder, the app will dig in in the folder to display all it's content. But if the user taps a cell that links to a file rather than to a folder, I want to transition to another segue that has a text editor.
I have the dig in logic written up and it works like a charm, but I can't seem to link a single cell to two different segues. Whenever I try to link the segue to my text editor, the previous segue disappears, so I can't link to two segues with the same cell.
What are some alternatives to do this? Naturally, the cells are dynamic. I tried to clone the cell and link to the other segue, but my app would crash because dynamic prototypes can't have more than one cell, apparently.
Well, I'm not exactly sure why, but I try adding two cells this time (one will represent folders and another one will represent items) and it didn't crash this time... So now I have two cells that open the respective queues when tapped.
Related
I have an app with some tabs at the bottom (UITabViewController), and most of the tabs also include a toolbar at the top.
The user needs to be logged in to access one of the tabs -- let's call it the "My Account" tab. Once they are logged in, they will either be shown their profile information, or if they haven't set it up yet, then they'll be shown a dialogue that explains the benefits of filling in their profile along with a big button that says "Get Started". All three of these screens have tabs at the bottom and a toolbar at the top. So the views I'm making only take up the middle portion of the screen -- therefore they need to be loaded as subviews. In essence, I'm trying to display one of three different subviews based on the user's current state, and I need to be able to switch these subviews with one another whenever the user's state changes (such as when they log in).
I originally created three separate "layers" for these subviews and just used setHidden to switch between them, but that has the big disadvantage of initializing all 3 views regardless of which ones are being used. I'm also not sure how to animate the transition when I'm just hiding/unhiding them.
Ideally, I would like to create three separate nib files (one for each view) that share the same viewcontroller (the parent controller), and just load them in dynamically based on the user's state. So if the user is not logged in, I'll load in the "Login" nib and then use addSubView to add it to the screen. When the user logs in, then I can load one of the other nibs as a subview and then use an animation to switch out the subviews.
The problem I'm having is that all three of the subviews are simple enough that I just want to keep the logic for handling their button clicks within the top level view controller (the "MyAccountViewController"). For example, I would like to be able to handle the click event of the "login" button within the same view controller that is responsible for displaying the user's profile information. I don't want to have to create a separate view controller for each of the subviews.
This is what I'm currently doing:
- (void)showLoginView {
UIView *loginView = [[[NSBundle mainBundle] loadNibNamed:#"Login" owner:self options:nil] objectAtIndex:0];
[self.view addSubview:loginView];
}
It just crashes on the "addSubview" line with EXC_BAD_ADDRESS. By the way it is behaving, it seems to be running out of memory, possibly due to an infinite loop or something. I have a feeling I'm WAY OFF on the solution here.
Is what I'm trying to do possible?
I would also be interested in learning about any best practices for handling login screens. I've been having a lot of trouble figuring out the best workflow for an iPhone app. I'm used to writing web apps (and yes, a login is necessary -- this app is tied to a website).
Thanks!
EDIT: I've considered writing a separate view controller for each of the subview nibs. These view controllers would handle the button clicks within their respective nibs and then use objective-C's delegate feature to propagate the event up to the parent view controller, but that's a lot of extra code I'd like to avoid if possible.
If you haven't already, I'd double check your connections in that nib and NSLog the class of the var at index 0 to make absolutely sure it is a UIView.
My advice: scrap the nibs. If you can't do it in code, why even bother? I only use nibs as a layout tool, and never package them with a binary. Just make UIView subclasses instead and save yourself time, memory, code, and storage space.
As for your login screen idea troubles, when I'm stuck, I visit the Mobile Design Patterns Gallery for inspiration. If you would like a more... -Expert shall we say- opinion, visit SO's visual cousin ux.stackexchange.com
I'm working on my first app and I've issues on how to layout some of its logics.
Basically, what the app is supposed to do is to show a first screen when launched where user can fill in some values and press a button that opens a tableview which shows results. The first screen (view), outlets and connections are all working fine. The issue I'm having is how to leave this "home" search view and show the results to the end user on a table view. Right now, I've only 1 view with its related View Controler and this controller handles the tasks of taking user inputs and get results throughout a HTTP post request.
I need your guidance...Thx in advance
Stephane
Is there a reason that this all has to happen on one screen? iOS is set up to allow for this to happen very easily and (I think) attractively by using a UINavigationController and pushing in a new view controller (could be a UITableViewController or simply a UIViewController that contains a UITableView).
If you MUST have all of this take place in one view, Swastik is correct that it will require some view acrobatics. One way to do it attractively is to use the UIView animations introduced with iOS 4.
Here's Apple's UIView documentation: UIView Class Reference
Specifically, check out the CLASS methods of:
1. animateWithDuration:animations: (with or without completion:)
2. transitionWithView:duration:options:animations:completion:
Note that these methods will require you to learn a little bit about blocks, but it's worth it and I think blocks give tremendous power!
With the methods mentioned above, you could fade out your form and fade in your tableview, or maybe just move the form off-screen while the table view flies in. The possibilities are limited only by your imagination.
u can add a table in ur xib.Initially make it hidden, & when u need to show it unhide it & also if u want to update table's data , you can reload the data of the table.
I have a very large form to build in my ipad application and I'm note sure which approach( between create multiple views in or multiple viewcontrollers ) to follow. Well, I have decided to split may form in logical sections, so I want use a splitviewcontroller with a root( a tableviewcontroller with the sections) and multipleviecontrollers for each sections. When the user select a row in tableview I will show the correspondent viewcontroller. I'm saving a reference for each viewcontroller in my app_delegate and the app_delegate also is the responsible for change the viewcontrollers. Is this the best approach? There is other approach to follow? About the multiple view I was thinking to put multiple view in the same xib file and then choose based in tag as the use tap the row in rootviewcontroller's tableview.
Thanks in advance. And sorry for my bad english.. Learning!
I will say this on the subject: currently, having multiple view controllers on the screen at the same time can be problematic if you're not using one of Apple's existing classes, such as a UISplitViewController.
The main issue is that important events your view controllers will want to respond to (rotation events, etc) won't be passed down to them. It's not a huge pain, it's just something to need to take into account - you'd typically create your own parent view controller that could pass these events down to its children.
Now, you are using a split view controller, so alls well on that front. There is no provided way for detail and master controllers in a split view controller to communicate with each other, but Apple recommend you employ a standard delegation pattern. If your application is fairly simple this could certainly happen in your app delegate as you do now.
If you're targeting iOS 5 only there are some changes that are relevant regarding multiple controllers on the screen at the same time, but I can't discuss them on here because of the NDA. You should go to Apple's developer forums (devforums.apple.com) to learnmore.
Sounds like I'm trying to do the same thing as you (large insurance forms here, how about your project?) Unfortunately I can't help out as you're a bit ahead of me. I've been able to flip back and forth between 8 detail views by tapping on the 8 rows in my UITableViewController, without keeping a reference to either the current or previous one anywhere. The data I enter into various TextFields stays where it should.
I currently have a xxxViewController.h/.m and corresponding .xib file for each detail view. That's an awful lot of code, but I couldn't see any other way to do it. Now I'm having a problem getting my button pressed handlers to fire. Also I've still got to put a database behind these screens.
Were you able to overcome your issue?
Thanks,
Jeff in Alabama
I'll try to explain this as best as i can, but i appologize if it gets too confusing - I've been stuck on this problem for many hours now.
In my application i have a search screen where the user will be able to select a bunch of criterias to perform the search by. Some of these criterias consists of fairly long lists of values to choose from and therefor i want a tableview on my searchscreen which have 4 rows - Each row representing a criteria that the user can set.
Once the user clicks on a row i want to push a new window in my navigationcontroller which consists of a new table containing the selectable values for that criteria - Once the user clicks on one of these rows on the new window, i want the selected value to be sent back to my main searchscreen and pop back to my search screen.
What would be the best way to do this?
Elaboration:
My searchscreen is called SearchViewController and is contained in a navigationController.
SearchViewController contains two sliders and a tableView with 4 rows called "Searchtype", "Property type", "Salestype", "Area" and a searchbutton. If the user clicks on "Searchtype" then i want a new view to be pushed in the navigationController which should contain a new tableView with a bunch of rows representing different possible values for the "Searchtype" criteria - The same goes for all 4 rows in SearchViewController.
When the user clicks on one of the value rows in the newly pushed tableView i want that tableView to be popped away and the selected value sent back to the SearchViewController allowing the user to either select more criterias or push the search button to actually perform a search based on the selected criterias.
But i can't figure out the best way to do this?
I really appreciate any help i can get - I'm going nuts trying to figure this out :)
Btw. i don't use Interface Builder - All UI elements are coded manually.
5 ways to do it here:
1) Let the Search View Controller be the delegate of action in the Search Type View Controller, so that when the user selects a search type, it will be informed. Use protocol for proper check at compile time if you want, and remember to use assign instead of retain for the delegate, to avoid circular reference.
2) Set the UINavigationController delegate to Search View Controller (or whatever class you want to control it), and listen to the event when the Search Type View Controller is popped out.
3) Implement a "refresh" function in viewWillAppear: as suggested above, but this is not recommended, because the implementation of viewWillAppear: sucks and not reliable at all. Maybe good for simple app, but when the structure of your app gets complicated, forget it.
4) Use NSNotificationCenter. Your Search View Controller will observe all changes to search criteria, and in each child view controller, when the user changes it, post a notification. This is more complicated, but much more powerful and flexible than all the methods above.
5) Similarly, you can use Core Data to store all search criteria in an object, and listen to changes in that object using KVO. This is a bit more advanced and may be overkill, but if you know KVO, it makes life much easier in Objective C, so probably worth taking a look anyway.
Btw: It's good to do all the UI by hand coding to understand the concepts at first, but try to move to Interface Builder whenever you can. It is a much recommended way to work (there are countless threads on this in Stackoverflow or on the web, with more elaborated discussions on why IB is better).
I'm trying to create a single class and xib where a tableview can be reloaded with different core entities depending on which toolbar button you press. I've got my code working and can see it loading the different entities in my fetchedResultsController. however when I message [self.tableView reloaddata] my table view delegates are never called. Does anyone know of an example where I could do this with out resorting to having 4 different viewcontrollers?
1- Is the delegate of the tableView set ? Can you show us the code please ?
2- You can use 4 different tableViews and hide/show them when you press the toolbar button.
But I think the first solution is the best.
Well one thing I'm learning about iphone development is if your trying to do something that's difficult you're probably going about it the wrong way. After initially thinking I didn't want to use a tab controller and four views it looks like that's what I should really do. I thought it would be easier to keep all the code in one class file, but quickly that gets out of hand. Better to have 4 view controllers and load as needed