Create event in hourly calendar in table view in Swift - ios

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.

Related

Dynamically create buttons inside of UIView

I currently trying to implement a dropdown menu. The content of this menu is supposed to be several buttons. The amount of the buttons is determined by the size of the struct array carsArray.
The title of the button shall be each structs value name:
for n in 0...carsArray.count - 1 {
button.setTitle(carsArray[n].name, .normal)
}
This menu shall slide in from above. To do this, I created a UIView - how can I dynamically create as many buttons as there are entries to the carsArray inside of the UIView?
Additionally, am I right to assume that with every entry the UIView's size have to adjusted? If so, how to also do this with every entry? Or do I have to create a table view to do so?
Is there another, easier way to create such a dropdown menu? Maybe with already from Apple given classes?
The way this can be achieved is by using a UITableView. To implement the opening and closing of dropdown, you would need to add or remove the cells or animate the height of UITableView. To close, you would make the height as 1 row height and to expand, you would make it maximum height or total number of rows height.
This is the library that I created a few months ago for one of my apps. It uses a UITableView to create the drop down. Have a look at this.
Let me know if you face any problem using this. Would be happy to fix.

Create a listing inside of a ScrollView

I am writing a Swift app, and on my main screen I have a long scrollview with several regions of content in it (upcoming events, announcements, and then featured products, and finally some basic info). So it's this really long scroll, and you can swipe down to the bottom.
So visualize 4 boxes, if you will, stacked vertically.
The 3rd box shows featured products. This can be anywhere from 1 to 30 items, depending upon any filters the user has in their settings.
My first try was using a UITableView for region#3 inside of this parent scrollview, but the problem is it only shows the first few items/rows and then the rest you scroll inside the table (which is the default/natural behavior of a table, right?). Unfortunately, the requirement I have is that the inner table can't scroll - it needs to display everything at once and you have to scroll (in the main UIScrollView) to get to the bottom (not scroll inside the inner uitableview scroll). Also, everyone seems to say don't use UITableView inside of a scroll.
So how do I create some sort of list where I create one template (like how you would in a xib/tablecell, and then assign a data source to it, and then repeat down without scrolling? Should I use a tableview after all, and just make the height of it very high and turn scrolling off?
Do I somehow instantiate xibs in a for loop and assign them dynamically to some view?
Thanks so much!
Sounds like you want a Table View with Grouped style. That would make it fairly easy to keep your "4 boxes" segregated, and your "3rd box" would simply be 1 to 30 rows in that section.
On note: you don't want to have a "very tall" table view - or any other type of view, for that matter. You want to allow iOS to manage memory for you, and to load and display only those parts of your content that is visible at any one time.
In other words, use a table view like its designed to be used :)

Custom Cell merge in UITable view

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.

how to draw multi-day event rectangles across multiple days on a month-view calendar on IOS?

What approach is recommended to draw multi-day event rectangles across multiple days on a month-view calendar on IOS? Keeping in mind the goal to be able to drag/drop the event bars around on the calendar
Two options that come to mind, however I'm not sure which would be best (or if there is another) is:
Use UICollectionView (with UICollectionViewFlowLayout) - but then there wouldn't be one object per multi-day event would there? i.e. Every multiple day event would need to effectively draw a portion of itself separately in each day cell, and ensure the drawing lines up to appear as single bar
Draw the calendar yourself, so you can put multi-day rectangle bars for ease in drag-droppping, but then you wouldn't get the rendering support from the UICollectionView associated with continuing to scroll through the calendar and it creating/removing cells as required?
Any suggestions/direciton welcome.
I would suggest the following:
create your own collectionviewcell representing a day (you might probably
already do this).
add an 'events' property to the cell holding
all events which start, end or include the day (you set this in collectionView:cellForItemAtIndexPath:).
you have to decide if you draw the rectangle by yourself (overriding drawRect) or if you
add a view (eg. imageView, ...). In any case: There are
4 scenarios:
The event starts in the cell but ends in another cell
The event starts in the cell and ends in the cell
The event starts in another cell and ends in this cell
The event starts before the cell and ends after the cell
For each of this scenarios, draw the corresponding graphics or add the corresponding view. If you use a plain colored rectangle / view, this ist very easy, if the rectangle has a border or round corners, you have to draw different rectangles for each scenario.
If you drag the event, just adjust the dates of the event and be sure it is removed / added from / to the corresponding cells and repaint the cells.
An alternative (probably easier) way to the 'events' property might be, that the cell can inquire the corresponding events from somthing like an event manager.

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