Custom Cell merge in UITable view - ios

I am working with Custom cell merge functionality in my UITableView.
I have Table view with 3 different column. First column is for username, second is for Facility that is provided to user and last is for the permission that is given to user for the particular facility. And currently my Table view shows as follows:
As you can see in the above image the Username cell is repeating, if username is same for different facility. So it's not looking what I want.
I want to merge Username cell column to stop repetition. And want to merge cell as below given image.
I got count of Different Username which is repeat in database table with NSSet but i did not get clue how to merge this cell.
Please help me for this and provide some sample code for the same if possible.
Thanks in advance.

TableViews are single column. You may have to use 3 TableViews to achieve your UI.
If you use 3 TableViews - all you need to do is set the height of the cells in the first tableview (User) as multiplers of number of respective rows in the second tableview (access).
For example, the height of 'User 1' cell would be 5 times the height of a cell in the second table (access). The height of 'User-2' would be 2 times the height of a cell in the second table (access).

The best way is to use a section.
But still if you want to make UI like that, then the process is as below.
If you have data like in 2nd image then you need to create 1 row for 1 user.
Then you need to create 2nd and 3rd column, by dynamically.
i.e. if User 1 has 5 row, then you need to create 5 Custom view in User 1's Cell programatically.
Then you need to manage height of cell also programatically.
i.e. if User 1 has 5 row, and you take height of 1 row is 50 then you need to make cell of (5 * 50) = 250.

You can achieve this output by taking only single UITableView.
Create your UITableView as shown in image.
Follow below steps to get the desired result.
================================================
Create a UITableView with dynamic row height. (using
UITableViewAutomaticDimension)
Create a UITableViewCell as shown in image like Left side is UIView containing UILabel as User.
Create UICollectionView for right part of your TableViewCell containing two 2 columns for facility and permissions.
Disable scrolling for the CollectionView.
Give Height Constraint to the UIView (UserView) created above.
Now to populate your tableview:
Get the number of count Facility for every user and set Height of the UserView as:
facilityCount * CollectionViewCell item height
By this way you can achieve your output in very efficient way without any multiple scrolling issue.

Related

Create event in hourly calendar in table view in Swift

I am trying to create a daily calendar, like the native Apple one, that allows you to add an event that takes up part of a row or multiple rows. What would be the best way to go about doing this? I already have a table view built that displays the times by creating a custom separator line in each cell.
Should I be trying to use CGRect and create multiple prototype cells for each 15 minute interval (events will only be as granular as 15 min most likely)? Or would you layer a CGRect on top of the table view in a certain position? Events will not overlap each other, which should hopefully take some complexity out, e.g., not having to deal with events/blocks that are half the width.
Ideally, a blank row or an event should both be selectable so that an event can be added or edited, respectively.
Add two separate prototype cells one for no event and one for added event. You will of course have the data source array with you (I assume), from which you can detect for event is present on selected row in did select row.
Or else add flag for the same to check if event is added on particular cell index.
P.S. You can use UITableViewAutomaticDimension property for managing height for cells.

How can I deploy content below a row in a UITableView?

Can somebody help me to do the following in Swift:
I have two elements called Topic 1 and Topic 2.
I need to click on the Topic 1 (in the down arrow image), then deploy some content just under my Topic 1 section.
I use a UITableView to display the data (topic 1 & topic 2 rows), but I don't know if displaying content below each row like the following image is possible with an UITableView.
Anyone know a way to resolve this?
Thanks!
Two high level options:
Display topics as section headers instead of rows. Detect tap of
section header and track the "active" section in your table view
data source. Only return a row count greater than 0 for the "active"
section. When the "active" section changes, reload the old section
and the new section.
Create a cell that displays both the "Topic" and any details. Implement the table view's delegate and return a height that shows the details only for the "active" topic. For all other rows, return a height that will only show the header. When the selection changes, reload the old and new rows to animate the height changes.
Don't try to "deploy the content" below the cell. Add it to the cell. In other words, you modify the cell or replace it with another cell built exactly to accommodate this extra material.

How to add static tableviewcells on runtime in IOS

I'm new in objective C.
I am using an static table view controller to load data related to my Class GAME.
I have 2 sections, in one section are cells related to the game, and in the last section y want to add the players who were in the game, which can be as many as I want. For this I created a button in the last cell of the first section addPlayer.
I want to create a new row in the 2nd section each time I touch addPlayer. how can I achieve this?
Thanks!
PD: Do I need to have the first row of the section 2 added by story board? Don't I?
if you want to add cells each time you add a player you could have, for example, a NSmutableArray which will contain the players and when you create a player you add it to that array and call the table's [yourTable realoadData] method. Then, your UITableViewController cellForRowAtIndexpath: method should loop through that array and add the cells dynamically. Use the array's count to keep track of the indexPath. You might have to keep track of the section so that you add the initial cells of the first section (the Date cell, the Pozo cell and the button cell) Keep in mind you will need to add a prototype cell in the Storyboard and set its identifier so that you may reuse the cell otherwise you will have to keep creating and adding cells to the table, which is not efficient.
Let me know if it works or if you have more questions!
You can't add static rows at runtime, you should go for dynamics.
What you can do, but only if you are using a Table View Controller, is create the maximum number of rows that you need, and override the – tableView:heightForRowAtIndexPath: to return zero height rows, at the indexPath that you don't need to show.

Getting data from a custom cell

I am dealing with a problem when I try to get my data from custom cell which has two different textfields.
The custom cell was implemented this way:
http://imageshack.us/photo/my-images/441/screenshot20120726at434.png/
And the table view looks like this:
http://imageshack.us/photo/my-images/849/screenshot20120726at431.png/
What I want to do is that when I press SAVE button from the right top corner I should get the values from the two textfields and also the switch status. I don't know how to manage the cells in order to do that. Thank you in advance!
You can create three index paths with section 0 and rows 0, 1, and 2. Then ask your table view for cellForRowAtIndexPath:. You know which type of information you want from each -- the same as what you stored in your datasource method -- and can read it from the matching text field or switch.

table view with multiple columns

i want to display name phone number and salary of a employee in an ipad in the form of table with multiple columns for that i take three table views and successfully displayed data in them . the table views are scrolling independently.but i want to implement if one table view is scrolled the second and third must be moved parallel. can any one please tell me how to implement that one....
If you want all your UITableViews dependants and scrolling at the same time, there is no reason to create multiple table view.
You can just create un custom UITableViewCell with the layout and style you want! This will be easier and will consume less resources.
find out position of cell in first table depending on that change position of cell in next table.
You can use following property of UITableView - – scrollToRowAtIndexPath:atScrollPosition:animated:

Resources