I try to put a View to the bottom of the screen on my UiTableView. How can I do that? Now it is still the last row. I searched for it but I didnt found someting useful. I hope you guys can help me
Please put UIView below the UITableViewCell like this.
Drag the desired view to the bottom of the UITableView's contents, i.e. below all of the table's cells.
You can add this line inside your code for your table view cell bottom
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 60))
footerView.backgroundColor = UIColor.whiteColor()
return footerView
}
Related
Ive been at this for a while but cant seem to crack it in swift
I want a user to be able to select an image in uicollectionView and for that image to appear in a detailed view controller, i can do this quite easily with a peice of text,
and i can do this when there is a static array of images preloaded. but i cant seem to get anywhere with a collectionview which is loaded with images from a camera.
I understand i need to use
override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
}
and this function to isolated selected cell.
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
}
I do have these outlets
#IBOutlet weak var collectionView: UICollectionView!
var images = [UIImage]()
image picker stores all images to this array by
images.insert(newImage, atIndex: 0)
when the array would be passed to the detailviewcontroller, i understand that would have to be copied into another local array and then how would i get the current image that was highlighted to be shown first, perhaps using indexPath.Row
Regards
I'm not using segues, and actually I don't quite understand what your problem is, but I'll try to show you how it could be achieved.
First of all, you have an array with images, so I believe your image should be accessed as images[indexPath.row]
let's suppose that you already have UIViewController class with UIImageView in it.
if so, you can write something like that:
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let myVC = MyViewController()
myVC.imageView.image = images[indexPath.row]
self.presentViewController(myVC, animated: true, completion: nil)
}
for modal or
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let myVC = MyViewController()
myVC.imageView.image = images[indexPath.row]
self.navigationController?.pushViewController(myVC, animated: true)
}
if you want to show it as navigational.
I believe that with segues it's basically the same but I think you have to use func prepareForSegue for, you know, preparing the segue (func performSegueWithIdentifier will just perform it). In prepareForSegue you should check identifier of your segue
if segue.identifier == "myIdentifier" {
//your code here
}
and if this identifier is right, put your commands to your myVC there.
I've a TableViewCell with a UITextView, which content is not aligned and cutted at bottom at the first display:
When I scroll down and then up to the top, everything is fine:
My cellForRowAtIndexPath to get the content from a fetchedResultsController is simple:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TextViewCell") as! TextViewCell
let data = self.fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject
let text = data.valueForKey("textDu")!.description
cell.textContentView.text = text
return cell
}
How can I get the result after scrolling after start???
Use sizeToFit() after adding content to your textContentView.
cell.textContentView.text = text
cell.textContentView.sizeToFit()
Make sure for sizing cell
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "onContentSizeChange:",
name: UIContentSizeCategoryDidChangeNotification,
object: nil)
tableView.estimatedRowHeight = 89
tableView.rowHeight = UITableViewAutomaticDimension
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func onContentSizeChange(notification: NSNotification) {
tableView.reloadData()
}
Hope it helps you.
In conjunction with #Ashish Kakkad's answer you may want to try to set heightDimensions in viewDidLoad or viewWillAppear:
yourTableView.estimatedRowHeight = 30.0 // Put a real estimate here
yourTableView.rowHeight = UITableViewAutomaticDimension
Use auto layout code to tie the bottom of the cells contentView to the bottom of the text box. When the text box resizes it'll expand the cell with it.
This is in addition to Asish's correct suggestion about automatic cell heights and is quite a high level suggestion as you need to do a few things to get auto layout working right in tableview cells but there's ample examples on that out on the web.
oh, oh. Think I found something. I removed the existing contraints and then I've tried to "add missing constaints". The result was thas the error "Failed to automatically update constraints". Seem's I've a problem with my storyboard-file...
I am using UICollectionViewDataSource & UICollectionViewDelegate in my personal ViewController subclass file. I can now click on the cell in CollectionView and navigate to the child ViewController I want, but the target's viewDidLoad method is always run before the didSelectItemAtIndexPath, so I can't get the selected cell's info before the view comes out, for example to get the label name of the selected cell.
Below is the codes I did for now, line 2 is always comes before line 1, but I need to get line 1 first, any ideas?
in UICollectionView's ViewController with datasource and delegate:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("1") //line 1
}
in target's ViewController:
override func viewDidLoad() {
super.viewDidLoad()
println("2") //line 2
}
P.S: push segue is using from main to target.
Use didHighlightItemAtIndexPath instead of didSelectItemAtIndexPath solved my problem.
Use prepareForSender:segue: instead of collectionView:didSelectItemAtIndexPath:. The sender is the cell that was tapped. If you need its index path, you can get it from the collection view using indexPathForCell: (passing the sender as the argument).
I have UITableViewController with UISearchBarController.
I'm trying to add a custom view between the table and the search bar like this:
First of all, in iOS8 (not sure if it the same in previous versions) SearchBar is added as UITableView's header and adding additional view to the header removes the SearchBar.
Secondly, it is not possible to add a custom view for the FIRST section using viewForHeaderInSection like this:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
let view = UIView()
view.frame = CGRectMake(0, 0, 320, 100)
return view
}
return nil
}
The code above doesn't produce anything. However, if I return the same view for section == 1 then I get a view displayed
Does anyone know any solutions for this? I see the only way to solve this by skipping the first section and display all the cells starting from the second section
I have a tableView and want to add a toolbar at the bottom with a sync button and the latest sync date (like on the Mail-app on the iPhone). But the Scrollbar should be fixed, so that it doesn't move when I scroll trough the table view.
Right now, I'm just adding the searchBar programmatically by:
self.tableView.tableFooterView = self.toolbar;
Another problem linked here is the fact, that I'm using the MasterDetailsView Controller template of Xcode. But I can't just drag a toolbar into my MasterView (containing the tableview). My first guess is that its just fixed because of the template I used but I'm not quite sure about it.
Thanks in advance!!
Instead of using a UITableViewController try using a plain UIViewController which conforms to UITableViewDelegate and UITableViewDataSource. Add a UITableView as a subview to the view controller's main view and link its delegate and datasource to the view controller.
Now, you can add any other UIViews to the main view which will appear fixed on top of the UITableView.
In your Story board for that ViewController, drag Bar Button Item to the Bottom after the tableView and in viewDidLoad method.. do the following..
self.navigationController.toolbarHidden = NO;
I think I found a really good solution to this.
In the storyboard view, drop the toolbar out of the Tableview. In the story board view this will leave it 'floating' above the view and the tool bar will no longer appear in your compiled code.
Too fix this, add the following to your view controller code
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v = UIView()
let toolBarView : UIView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
mainToolBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44)
toolBarView.addSubview(mainToolBar)
v.addSubview(toolBarView)
return v
}