I don't see my buttons when running the simulator - Xcode10 - ios

I was trying to follow a tutorial online but the version that was being used was older than the most recent Xcode10.
I have added a navigation controller and added buttons to the controller...
navigation controller with buttons
But when I run the simulator, I do not see the 2 buttons that I created....simulator without buttons
Any ideas why this would be the case? All help is appreciated :)

To calculate the height, UITableViewCell rely on the content of the cell and to be able to do that you should add constraints to the buttons you have already added.
or you should implement the delegate method
func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat

Related

Reordering a UITableView: notification when user first starts dragging with the handles

I have a UITableView with cells that I want the user to be able to reorder by dragging them up & down, using the "handles" on the right side of each cell. I do NOT want to implement "drag & drop" functionality, because the data behind these cells makes no sense outside of this table (and implementing NSItemProvider looks to be an ugly process, given the data behind the table view & its cells). So far, everything is implemented & works fine. Looks somewhat like the results of this article.
The next step is, I'd like to know when the user has "lifted" or started to move a cell -- similar to the dragStateDidChange ability when one IS using drag & drop. I want to get this notification even before the cell has been moved out of its place -- as the UI turns the cell background white & "raises" it above the table.
How can I get this notification, without implementing "drag & drop"?
Things I've tried that don't accomplish what I want:
Recognizing a long-press gesture: I do use Gesture Recognizers on these cells for taps & such; it seems that when the user touches the drag handles to reorder the cells, this action does NOT fire a long-press Gesture. Tried that, no success.
Will-select-row-at: I implement the function func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? within the UITableViewDelegate code; it isn't called when the user touches the drag handles.
targetIndexPathForMoveFromRowAt: The func func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath fires when the dragged cell changes position, but not until then; it does NOT catch the start of the lift/drag process that I'm looking for.
Likewise, willBeginEditingRowAt and shouldHighlightRowAt aren't called either.
Various scrollView functions: they all get called when the user is scrolling the whole table, not when the user is reordering it.
Watching for "set editing": the drag handles need to always be present, so "editing" is always set to true.
Somewhat similar question, unfortunately without an answer that I can use (and also not in Swift).
I suspect that there must be a simple notification that the cell has been lifted and is being dragged using the handles, even if it hasn't been moved far enough to be above or below its old place yet. After all, the OS "knows" about this because it changes the background and adds shadows & so forth. Any help accessing that notification so that other code can respond to it as well would be most appreciated!
It's a little strange that these are not documented, but you can define the following functions in your UITableViewController (or in the UITableViewDelegate) which will be called when cell dragging starts or ends, respectively:
#objc func tableView(_ tableView: UITableView, willBeginReorderingRowAtIndexPath indexPath: IndexPath) {
// Dragging started
}
#objc func tableView(_ tableView: UITableView, didEndReorderingRowAtIndexPath indexPath: IndexPath) {
// Dragging ended
}

UITableViewCell content is sometimes overlapped by delete button (on swipe)

I've implemented swipe to delete in UITableView a lot of times before, but never faced this problem before. In my last app delete button sometimes (not always) doesn't shift cell's content, but just overlaps it. See attached screenshot.
I use standard iOS functionality for this:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
Probably, somebody already faced with this issue and know how to fix it?

Navigating from UITableView to another ViewController and then going back to the TableViewController causes some elements to disappear

I have a strange issue in my notes app.
I have a ViewController that is a UITableView delegate and datasource (I do not use UITableViewController)
The table view is a list of notes. Clicking one will open the editor view controller for the selected note.
When I click a cell, then click the "Back" button to go back to the table view, some elements of the table view UI appear missing.
Here is a before and after screenshot of the table view:
I am using Realm mobile database to store the data for the notes.
When I debug I see that data is actually populated in the cells, it just does not appear on the screen.
I tried removing the app and reinstalling it
I tried deleting the storyboard and rebuilding everything from scratch
I check the cellForRowAt indexPath and made sure the data is being populated.
Update - code for cellForRowAt indexPath::
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: NoteListCell.identifier, for: indexPath) as! NoteListCell
let object = results[indexPath.row]
cell.configureCellWith(note: object)
return cell
}
I even tried adding a background color to the labels that disappear to see if they are still there or is it just the text that's missing (it's not the text, the entire label was gone).
I don't have anything special in my code for handling the tableview data or navigating between view controllers. I have nothing in my viewWillAppear and viewWillDisappear methods for both VCs that causes this (i tired removing everything from those methods but the issue remains)
Anyone has any idea on what else I can check?
So I still don't know why this was happening, but I installed Xcode 9 beta and ran the project from there (I was using 8.3.3 before) and the problem disappeared.
It's possible that reinstalling 8.3.3 would also solve the issue.

Can't Swipe Due to editingStyleForRowAt

There seems to be an error that's impossible to avoid, but I'm hoping someone can do the impossible.
In a UITableView editMode there's a lefthand delete indicator (red circle with a white line):
I just want the drag / drop grip on the right, so I get rid of the indicator by calling:
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return .none
}
However, it also seems pretty clear that if you want the ability to swipe for actions...
You CANNOT call the above "editingStyleForRowAt" method. So it seems like I'm forced to choose only one of the above features... oddly you can only return ".none", ".insert", or ".delete".
Anyone know of a solution?
In your case you should try with custom cell.
Please check below link.
I just assume, it is work for you, I am not sure.
https://www.cocoacontrols.com/controls/eecellswipegesturerecognizer

Full swipe to delete UITableViewCell and partial swipe to show options

I have a UITableView with prototype cells. If you swipe any cell to their left, two options are displayed on the cell correctly. This has been done with
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
Now, I want to also allow users to delete a cell. I understand the best way would be to make a complete on a cell swipe in order to remove it. This means, if there swipe is not complete, options will be displayed (as it is done now), but if the swipe is complete, the cell would be removed.
What code should I add to keep the actual behavior, but also enable to remove a cell by swiping it completely?
This repo has what you want. Have a look.
https://github.com/MortimerGoro/MGSwipeTableCell

Resources