Table with rows and columns in Objective-C for iOS - ios

How can I implement a table with rows and columns in Objective-C? I need to show a timetable: columns for week's day and rows for hours. I have no idea. TableView makes rows. Would UICollectionView be right for this?

You can use UITableView. But instead of using the default UITableViewCell, you have to create a custom cell with 7 labels equally spacing horizontally. Then you add 24 rows, each for one hour. And I think that's all you need, simple and straight forward.

That depends on how you want to eventually display it. What I usually do is create an array ( or two, or three if needed) and then pull from that when I want to display parts of it. The reason I said I might need one or two is that one might be for strings and another might be for for integers or float values. It all depends on the situation and you have to make sure you keep them synchronized programmatically.

Related

With IOS, is there a way of making a proper table with rows and columns?

I have been trying to find a way of creating a table, with rows and columns, for iOS. The UiTableView is basically a tree-structured list like this
Apple sample code, but because it's called a table view, it hijacks any attempt to search for a proper table.
There are a couple answers that suggest very clunky ways of doing it, like this SE Question, but it's quite old. Has the situation changed since this question was asked?
I've done this using UITableView by simply designing custom UITableViewCells that are segmented into columns. All the custom rows together certainly give the appearance of a multi-column table. When any of your data in a column or row updates, you re-render the tableView or have each row in charge of its own re-rendering (i.e. via an NSNotificationCenter message), and the whole experience for the user is as a multi-column table. If you setup your table's data as a separate row-column data model, it's pretty easy to get all the individual cells to go where they need to go with your custom UITableViewCell.
take a UITableView and on tableRow take 3 view of(width=1 and height=row height), each view ill be at equal distance from another one. and take label between these view at end it ill look like a table with rows and column

iOS Swift How to Extract Strings from All Selected Rows in a TableView

I want to loop through a TableView and extract the text from all the selected rows. I suppose I "could" create and maintain a special array that is updated every time a row is selected/deselected using the didSelect/didDeselectRowAtIndexPath methods. But creating a separate array seems like an extra step. Is there no way to let the TableView itself serve as the array and then simply loop through it and get the selected rows? What would the code look like? I'm new to Swift, so this might be a silly question.
Part of the problem is that cells are supposed to be reused, and when used this way it is not possible to loop through them all. You could get around this by using a unique reuse identifier for each cell, such as the indexPath itself or some underlying unique id in your model. Then, you could indeed loop through all cells and retrieve whatever state you desired from each.
You would, however, find your application crushed under the weight of too many cells being instantiated and kept in memory. If you don't have many cells you won't be killed, but try it with a big data set and your app will enjoy a very quick death.
It is far more efficient to store one array with a bunch of id's than a large number of memory-intensive UITableViewCells.
As mentioned in comments, you should work with underlying datasource, not the table itself.
For example if your table shows rows from Array, it is way more faster to retrieve strings directly from that array than creating UITableViewCells and get strings from them.
Get indices of selected rows using UITableView's property indexPathsForSelectedRows.
Query datasource for each row.
As has been said the tableview only handles displaying, your datasource is what powers the data shown if you think about it.
Plus as said before the tableview dequeues cells as they scroll on and off the screen.
The best way to achieve what you want is to add a property to your datasource for each element that will allow you to filter out the select properties easily.
How are you storing the state for each selected cell currently? As this is the same functionally you would use to be able to generate your selected text array.

how many cells to commence with in a UICollectionView for a Calendar? (i.e. with infinite number of dates)

How many cells to commence with in a UICollectionView for a Calendar? That is my understanding is:
UICollectionView is good in that it only instantiates cells it
needs to display, but then
You still have to add the cells to the collection view
So what is best practice if say your view would only show 10 cells, but you had unlimited cells (e.g. scrolling up and down dates in a calendar). Do you enter say 100 cells for 100 dates (say 50 either side of the starting date of interest) and then manually keep track of when you get to one of these edges and then add more? This would kind of be ashame the UICollectionView framework couldn't keep track of this itself no?
So overall questions therefore (sorry) are really:
How many cells (dates) should you be creating in the collectionview. Should it be limited therefore to say 100
Is there no support in UICollectionView to automate adding more cells in for you for a Calendar type situation where dates are endless if the user wants to keep scrolling forward or backward
Any what is impact on the caching strategy for UICollectionViewLayoutAttributes too?
There is a project on Github with a calendar based on UICollectionView
https://www.cocoacontrols.com/controls/rsdayflow
I have used this component in a production project.
You can easily change it's appearance since every day is a uicollectionviewcell.
This project is based on https://github.com/evadne/DayFlow
that can be a good base to create what you need.
If you want to build your own calendar it can help you to find response to your questions: the code is easy to understand, and the implementation is in my opinion quite neat
It depends on how much is visualized in one screen. If it is one month i would have one month before and one month later. If it is only a day, one day before, one day later. Then use this infinite scrolling trick. There are many examples outside. I didn't read through the following link, but the pictures visualize the idea nicely:
Building a Infinitely-Scrolling Gallery With a UICollectionView

Multiple columns in tableview ios

I am working on an app using objective C and Xcode.
For the moment I am using a table view and returning rows with cells containing an image thumb and title. My problem is that now i need to change the layout and for 4 of the cells I need to make them fall on the same row (so each article of the 4 should be 50% width). So basically create 2 columns but only for 4 of the articles. The rest remain on 1 column (full width).
I would add an image but I don't have enough rep points.
I know there is some thing like collection view...but I am not very familiar with that one and I was hoping maybe there's an easier way than redoing the viewcontroller and all the connections I already have created there.
Since I am already using tableview..what's the best way to change the layout to fit what I need now?
Based on what you're trying to do a UICollectionView might not be the best bet. I would create a second type of UITableViewCell for those rows with 4 columns. This should help Multiple Custom Rows UITableView?
You can use UICollectionView with flowlayout and variable cell width. There are many tutorials about it out there.
You can also try this library: https://github.com/bryceredd/RFQuiltLayout
Have you taken a look at this library:TSUIKit
If you just want to quickly arrange your data, this would be much easier than trying to wrangle with UICollectionView.

Is there a option to add a new row in shinobi grids?

First of all i am using shinobicontrols for developing interactive UI controls (Grids) for iOS using Objective c and please don't suggest me some other controls as an answer because i need to use only this.
I am half way stuck while using this control. i have downloaded demo code for grids provided by shinobicontrols (trial for 30 days). from : http://www.shinobicontrols.com/shinobigrids/product-tour/get-started-quickly-and-easily/
I was able to reorder rows and columns, edit contents of cell, re size column width by pinch gesture and much more.
But i couldn't add a new row or column to the existing grid. Just wanted to know whether this can be achieved.
Thanks in advance.
Edit the datasource (add/remove) item and just do [grid reload];
I think this should do.
The above answer seems to be correct. Adding my views Shinobi grids can be considered as UITableView cells, If you simply change the data source array of the tableview and call [tableview reloadData], number of cells displaying on the view will also change. There is no option to add a row still.
Look at this one. It is in alfa stage, but it will be quite a powerful in month or two, I would say. Any suggestions are welcome and it's free, of course. Number of rows and row content is fully controlled from delegate, so it is dynamic.

Resources