creating a scrollview with data coming from database and variable number of elements for ios - ios

So I was trying to create a sample ios application. As I am designing the app UI with the storyboard (and not coding), I find Xcode really hard to understand.
what I want to do is I added a scrollView to the view controller. now what I want to do in the scrollView is simple.
I want my scrollView to have buttons (vertically stacked) and it does some action on the basis of the data it is getting from the database. let's suppose it is getting links from the database and on a click of those buttons those links open. now the data may contain 10 links, or 20 links .. basically, we want it to be according to the database.
now if I was designing the UI programmatically it would look something like
ScrollView{
for loop...{
button("for example name coming from the database"
}
}
or atleast this is what I know of.
so how to do the same with storyboard ?
like we first take it's refernce to the uiViewController class.. and then ?

You need to add buttons programmatically if they are created dynamically depending on external non static data. Create new UIViewContoroller class and implement it with connecting storyboard file, the easiest would be to add buttons inside some kind of UIStackView which is inside scrollview imo, or by using UITableView if there are significant number of links to display.

Related

Adding a UIView based on a template in swift?

I've used UITableView before and like the way that the user can add a practically unlimited number of cells by entering information and the program uses a template. I'm wondering if there is a way to do this, but instead of using a table, using regular views or even buttons. For example, the user would tap a button, enter information, and return to the first ViewController and it would have a new view with the information in place of parts of a template that I designed.
Sorry if this is unclear. Basically I'm wondering if there is a way to make a table that is not as restrictive as a table, but uses several individual views in place of cells.
You can create re-usable views in the same way that you can create prototype cells.
Just right click in your project window, add new file and select User Interface > View. create it just like you would a prototype cell.
Then create a related class by adding a new swift file, link the two, create any outlets or actions you need and add any required logic.
Once you are done you can just load it wherever you need it, like so
self.headerView = NSBundle.mainBundle().loadNibNamed("HeaderView",owner:self,options:nil) as! HeaderView
You would likely need to pass in some required information, or setup the views frame or constraints.
I found a YouTube Video which should help guide you through the process. I've only skimmed through it so you may need to look around for a better one, but the general concept seems to be there.

iOS reusable and changeable ViewController

I'm creating an app to increase my knowledge.
I have a ViewController which receives information, and with that information he shows some Views. I've already done something like this but in the end that was a mess and had way too much work to change what I've done.
In my attempt I had some views in the same place as others and just changed the hidden property to NO if I didn't want them to be visible, at the time that was the best option for my knowledge(4 months of iOS) and I thought to myself that must be other ways and better ones to do this type of ViewControllers.
So now comes my question.. What is the best way to do a ViewController which can change accordingly to the information he receives??
A base ViewController and the others are subViews from that ViewController??
Example Updated: I can receive N type of news. Some have an image in the top of the view, others have a scrollview like a photogallery to show more than one image, others can have a title with an image and so on.
Others can have text, others one webview to show a video, others can have a collectionView to show some additional information.
What I would do is have several UIView subclasses. So the setup would look something along the lines of:
YourViewController has a view, that is only there to display subviews
Then depending on the data you receive you instantiate one of your UIView subclasses that are made to display the data you need ( you could also design them in interface builder and access them as a property on your UIViewController ) and add it as the subview to use
Whenever the data needs to change again, remove all the subviews and add the newly needed subview.
ViewController.mainView -> removeAllSubViews -> addNewSubView
Alternatively you could have multiple view controllers I guess, but it kind of depends all on how and what you need your views to do.
For instance if you need more than just a display of data, and some interaction / manipulation of your data you might want to consider using multiple ViewControllers

TVOS about App layout (Like in iTunes and similar)

I have played a lot with my app and I do not understand how to make layout like in for example iTunes (also many apps uses it).
How it is made? It is one big CollectionView, but with special Flow or it is TableView with many CollectionView?
Collection headers. In iTunes App if I select item (with adjustImageWhenFocused) under the header then the header will jump up and the item will not overlap the header. It is special magic or it is system behavior and I just do know how to use it?
Below is two screenshots about what I am trying to tell you and example with my app.
In iTunes there are movie preview page. With what type of View it is made? TableView,CollectionView or just ViewController with ScrollView?
I have read many sources and looked up demo projects, but nowhere I have found answers for this questions.
1) I think it would be a stackTemplate containing a couple collectionLists.
2) AFAIK the headers "jump up" on their own, no need to prepare anything special.
3) productTemplate?
For examples, see https://github.com/iBaa/PlexConnectApp, /TVMLTemplates/Default/Movie_OnDeck.xml (1) or Movie_PrePlay.xml (3).
Or check the gold source: https://developer.apple.com/library/tvos/documentation/LanguagesUtilities/Conceptual/ATV_Template_Guide/StackTemplate.html, plus other Templates.
If you want to use native Swift way it can be achieved in following ways:
You can use table view and have collection view within each cell. I am using same approach to achieve this.
We have focus update delegate from there you can find the focused frame of image view. With the help of focused frame and label frame you can check if they are intersecting or not. Based on that you can move label up and down.
This is native TVML template, in order to achieve in swift you need to create view using tableview and collection view.

drill down UITableView using storyboard in iOS program

I'm trying to develop an iOS app that has drill down UITable View. I got a drill down table view tutorial, but the number of UITableViews is static. What I need is a dynamic one. My requirement is simple. I need to access an FTP Server and get the directory hierarchy (I guess I need to store it in NSDictionary or in an xml file) and display the content in the UITableView. If it is a text file, I need to display it in some view, otherwise I need to display the selected folder's content in the same UITableView, and it goes on till the bottom of the directory hierarchy.
I need to use the storyboard.
I've had to make a something very similar to what your talking about in a previous application I worked on.
In that I created table views inside of table view cells with a button at the top to expand and collapse the view using the cell height.
This worked pretty well but since then I've found the best way to simply programmatically add ui elements to either your table view cells or view.
In both cases I created a management system using parent child architecture to hold your information.
I hope this puts you in the right direction :)

iphone/ipad how to handle lots of input fields?

I'm writing a app that contains quite a bit of input fields for collecting data.
and im wondering what are some good methods to display these kind of input fields, if there are too many to fit on a screen? so something like the add contact screen... where u can scroll down and there are fields there
my initial idea is to put them in a scroll view and then i can scroll through them, is there a tutorial to do this? it seems like the scroll view is more for dynamically displaying data like a text view, and not for static forms like i was describing.
if anyone has any different methods for doing this please post.
UITableview will match perfectly for what you need.
My friend wrote this which is a container view that automatically helps with moving fields out of the way of the keyboard - It will certainly save you some time if you don't want to use a UITableView:
https://github.com/mackross/GTKeyboardHelper
The other way as H2CO3 suggested is to use a UITableView. If it is a UITableViewController, then you get the moving out of the keyboards way automatically. You could build custom table view cells that are styled to have a prompt and a UITextField for input. You can also set the selectionStyle to UITableViewCellSelectionStyleNone to prevent these cells from highlighting when selected.
I think the third way is to do this with a UINavigationController (or a UIPageControl) and build a kind of wizard, where you go through various pages of related data. This might be the neatest way depending on how many fields you have and if you can group data into common sets (e.g. personal information, work information etc)
I had the same problem and found GTKeyboardHelper to be an easy way out.
After drag and drop the framework in your project, include the header file.
Download and open the example project, then drag the "Keyboard Helper" object from the objects section in the xib to the objects section in your project's interface builder.
Drag and drop all your views to be children of the "Keyboard Helper".

Resources