I want to add button or row end of uitableview. I used tableview footer but its not solution for me. I also tried others way but ı didnt found any result. How can ı pass this problem.
Thanks..
Use UIViewController instead of UITableViewController:
In storyboard add UITableView to your view controller
Create an IBOutlet for UITableView - connect it
Conform your view controller to UITableViewDelegate and UITableViewDataSource
set tableView.delegate = self and tableView.dataSource = self
In storyboard add a button bellow table view and set top button's constraint to be few (e.g. 4) points away from table view's bottom constraint
Create IBOutlet for button and connect it
Add height constraint for your button - set it to 0.0
Set button's title to empty string ("")
Create IBOutlet for button's height constraint and connect it
Check when your table view reaches the end - to check whether your table reached the bottom you can implement tableView:willDisplayCell:forRowAtIndexPath: and check if indexPath.row is the last item in your data source (there are other ways too so you are free to check them)
When your table reached the end - simply set button's title to your desired title with button.setTitle(for) and animate button's constraint to another height (big enough to see the whole button)
When button is pressed you can just do the opposite animation: set button's title to "" and animate height constraint change back to 0.0
Related
The Collection view cell would need to show and hide additional tools for the device being controlled. The button that collapses would be at the bottom of the UICollectionViewCell. Whenever the button is pressed it would animate downwards revealing the fan or lights extra features or animate upwards when hiding the extra features. I only need help with expanding and collapsing by using the button at the bottom of the cell. An image is attached showing an example.
Add a height constraint for your high/med/low selector.
Connect that constraint to var in your cell class like this:
#IBOutlet weak var checker1HeightConstraint: NSLayoutConstraint!
set that constraint to a value you want (either 0, for hidden, or 50 or 60 if not hidden)
have a method where you set the value:
func toggleControls(visible: Bool)) {
checker1HeightConstraint = visible? 50 : 0
setNeedsLayout()
}
If you are not sure how to set the outlet, just ctrl-drag from the constraint in you storyboard or xib to your custom cellView class. It will give you options to create it.
I have my tableview with search bar added in it.
actionsTableView.tableHeaderView = searchController.searchBar
I want my tableView appear with hidden header, which will appear when I scroll up.
As a reference you can have a look on Telegram/WeChat/WhatsApp messengers, they have implemented this feature.
Try this inside of viewDidLoad,
[self.myTableView setContentOffset:CGPointMake(0.0f, 40) animated:NO];
Note: Add your UISearchBar inside of UITableView
Add your searchBar and tableView in a view(say mainView).
Add mainView to the view controller and assign its top(topConstant) to -40(considering its the height of search bar) , and assign the leading,trailing and bottom to view controller.
Now assign scrollview delegate to your class and check if tableview is scrolled on top by checking its velocity.
now add Animation and set topConstant to 0.
I have UITableViewController, on top of it I placed an UIView and inside it there is a UICollectionView.
When collectionView data is empty I want to remove the UIView. I tried:
self.collectionView.removeFromSuperview()
and
self.collectionView.hidden = true
These removes the UIView but there is an empty space above my tableview. How can I get rid of it?
Edit: added a photo of my storyboard. Recommended View is not inside the tableviewheader.
It looks like the collection view is a table header view (the way you have positioned it in the storyboard).
Try setting it to nil if data is empty
self.tableView.tableHeaderView = nil
I haven't tried but this code should solve your problem.
self.tableView.tableHeaderView?.isHidden = true
You have placed Recommended View inside the table view - not on top of it. So you could have placed it as header or cell. So when you don't want it to be present, change cell pr header height.
The RecommendedView is a tableHeaderView. Try to have a outlet to the height constraint of the RecommendedView.
Set the height constraint to 0 in case you don't have any element in the collection view.
#IBOutlet var tableHeaderHeighConstraint: NSLayoutConstraint!
override func viewDidLoad(){
if collectionIsEmpty(){
tableHeaderHeighConstraint.constant = 0
self.tableView.tableHeaderView?.layoutIfNeeded()
}
}
I've created a tableview within Viewcontroller and inserted disclosure indicator, but it is not showing, because the right margin is not correct.
What I tried:
selecting table and click in xCode on "pin" button and set left and right to 0, select there all frames in container and clicked: add constraints
but without results.
How can i fix this?
I attached the problem as image. (i have added a frame to focus the problem)
Okay, there can be multiple reasons for which this can happen. For instance, one can forget to deck the cell with wrong identifier or may have set the accessory Indicator in a wrong way. My personal assumption is you probably have set constrain improperly.
So, I am just going to show you the whole process.
Step 1: Drag and UITableView inside your ViewController and drag a UITableViewCell inside that TableView. Select the Table View Cell and assign an identifier. Make sure, in your datasource method, -cellForRowAtIndexPath, you use this same identifier.
Step 2: Go to your View Controller and take an IBOutlet of a UITableView.
#interface MyViewController : UIViewController<UITableViewDataSource>
#property(nonatomic, strong) IBOutlet UITableView *myTableView;
#end
Step 3: Go to the connection Inspector of your storyboard and connect the UITableView with this outlet.
Step 4: Go to the implementation file of your View Controller and populate the datasource methods. Also make sure, you set your TableView's datasource to your view controller.
Now when you build and run this code you won't see the accessory Indicator.
The reason is you didn't set the constraints.
Step 4: Just set the constrains like the following and you are good to go.
This is my final view.
You need to change seperator inset inorder to remove left margin. Its set to default change it to custom and make left insets and right insets to zero. You can set the 'Separator Inset' from the storyboard:
Change Seperator insets to Custom and make left to zero
Try to programmatically set the width and height of the tableView like so...
#IBOutlet weak var resultsTable: UITableView! // connect to tableView
override func viewDidLoad() {
super.viewDidLoad()
let theWidth = view.frame.size.width
let theHeight = view.frame.size.height
resultsTable.frame = CGRectMake(0,0, theWidth, theHeight)
}
The problem was not the margin/layout.
To show disclosure indicator in tableview cell's, it is needed to select disclosure indicator from Accessory menu AND give a identifier for the cell.
Without given identifier the disclosure indicator is not showing.
How do you create buttons like the "Settings", "Notifications", and "Cash Out" buttons in venmo shown below? Also, is the scroll view they use just a UIScrollView or a modified UITableView? I can't figure out how to add things like the buttons or the picture with balance info and name to a UITableView.
For this example, I think it's easier to use a UITableView than to build a custom subclass of UIScrollView. If you want to customize the look of the table view's cells, initialize the table view with the UITableViewStylePlain style and give each UITableViewCell the appropriate backgroundView & selectedBackgroundView in –[UITableViewDataSource tableView:cellForRowAtIndexPath:].
For the "Settings," "Notifications," and "Cash Out" buttons, just add them as subviews of the cell in the first row of the first section. Use -[UIButton setTitle:forState:] & -[UIButton setImage:forState:] to give each button a title & image, respectively. Set the UIButton properties titleEdgeInsets and/or imageEdgeInsets so that each button's title appears below its image.
To add a picture with a name, bio, and balance at the top, use the tableHeaderView property of UITableView. In -[UIViewController viewDidLoad], initialize a UIView *tableHeaderView with the desired height and give it subviews, e.g., pictureButton, nameLabel, bioTextView, balanceLabel. Then, do self.tableView.tableHeaderView = tableHeaderView.
They have used tableView. It contains 3 sections. They have chaged customCell in each section. In cellForRow delegate method you get section. Accordingly you can change cells. In CustomCell you can add any view like buttons.