I've been struggling with this for awhile and can't find it answered elsewhere. Basically I need to edit a view inside the selected collection view cell. For example once a cell is clicked the label text inside that cell changes.
Here is what i need however it only works on tableviews
If I understand it correctly you need to get the selected collection view cell:-
if let cell = collectionView.cellForItemAtIndexPath(indexPath) {
cell.textlabel.text = "yourtext"
}
Related
here need some help T_T.
I'm design a page that use a collection View to display 4 different table view in 4 collection view cell. Therefore I design collection view in xib and put a table view in it, but in this case tableview have no prototype cell when it is designed in a collection view cell in xib , so I create another xib to handle my tableview cell.
The problem is , when Im adding "estimatedRowHeight" and "AutomaticDimension" in cellForRowAt below
let backgroundCell = detailCellTableView.dequeueReusableCell(withIdentifier: "baseDetailTableViewCell") as! BaseDetailTableViewCell
backgroundCell.setTitleLabelText(title: backgroundTitle)
backgroundCell.setContentLabelText(content: background)
self.detailCellTableView.estimatedRowHeight = 300
self.detailCellTableView.rowHeight = UITableViewAutomaticDimension
return backgroundCell
it would be none change tvcell
The cell size won't autosizing , the label in my custom cell is stacked.
I guess that the problem might be the prototype cell , but I don't know how to solve it..
This is because, this property is added to the tableview and you are adding it to cell.
Steps:
1) Create a tableview outlet.
2) add following code in viewdidload()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300
I am currently developing an iOS application in Apple's Swift.
I have a table view with table cells in it each of which displays the current time of a timer (it is not a real timer it is actually just a timestamp).
The application itself has a timer which updates the visible cell of the table view with the current states of the cell timers.
The application provides the possiblity to slide a cell which lets appear a delete button.
The problem I am faced with is that the delete button immediately disappears due to the fact that the cell is updated by the application's timer.
Here is the code where the table view cells are updated:
// Update visible rows in table
func updateTable() {
// Get all visible cells
let cells = timerTable.visibleCells as! Array<TimerTableViewCell>
for cell in cells {
let indexPath = timerTable.indexPathForCell(cell)
cell.timeLabel.text = String(timerArray[indexPath!.row].getRemainingTimeAsString())
timerTable.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.None)
}
}
I would be glad if anyone would have a solution/workaround for my problem.
Thank you in advance.
I think the simpler solution is to remove your reloadRowsAtIndexPaths call, and just update the timeLabel. You could try this:
// Update visible rows in table
func updateTable() {
// Get all visible cells
let cells = timerTable.visibleCells as! Array<TimerTableViewCell>
for cell in cells {
let indexPath = timerTable.indexPathForCell(cell)
cell.timeLabel.text = String(timerArray[indexPath!.row].getRemainingTimeAsString())
}
}
Because reloadRowsAtIndexPaths says to the UITableView: Hey, just take the rows at theses indexPaths and rebuild them from scratch. Ignore its previous state.
I have a UITableView with UITableViewCell's and once i select a cell it will display a checkmark for that cell until here its fine, but once i press the add button to add a new cell to that UITableView it will take me to another ViewController to write the text of the new cell and add it, so after adding it it will take me to the previous UITableView but without displaying the checkmarks to the cells that i have already selected before adding the new cell, is there a way to display checkmarks for the selected cells after pressing the back button from the other controller ?
Note: I am using Xcode with swift language to build my application.
The cells in your tableView is made with a array of some Object. In that Object you need to add a variable isChecked, and if it true, the tableviewcell at that indexpath will be checked.
you can do so by adding something like this in cellforrowatindexpath
if objectAtIndexPath.isChecked {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
So the key is to have a have a variable in the object you are using to populate the viewcontroller.
When you create the new item, you simple say isChecked = true, and then add it to the array which contains the items, and it will be checked automatically.
Am using custom tableview cell in my code. Please can anybody help me how to write the code for common friends cell. How can i get the names AMANDA,VIKA LEVINA,NATASHA,KATE,JESICA names in rectangular box.
For common friends and Facebook interest cells you can use UICollectionView and adjust cell width depends upon text otherwise you can use one of below listed controls.
https://www.cocoacontrols.com/controls/jctaglistview
https://www.cocoacontrols.com/controls/taglistview
https://www.cocoacontrols.com/controls/antagsview
you have to design two custom cells in your IB first for image view cell and other for list given below in your cell. create two custom cell in IB and design them according to your need and after that in your cell for row at index path method differentiate between these cell like:
uitablviewCell *cell;
if(indexPath.row == 0)
{
cell = [tableview dequereusablecellWithIdentifier:Firstcell];
}
else
{
cell = [tableview dequereusablecellWithIdentifier:secondCell];
}
For common friends and Facebook interest cells, You can use ANTagsView.
Using this, You can get tag view which you are showing in image.
So this view, you can add into your cell. For tags view, you have to pass array according to your view.
And set height of cell dynamically using heightForRowAtIndexPath method.
After that, you can get your view.
I have a button on a CollectionView that animates the labels on the CollectionView (slides them back & forth). I'm wondering if it's possible to also animate the labels on the cells using the same button.
I was considering collectionView:performAction as a possible solution, but I wanted to get some other ideas before sinking too much time into figuring out something that potentially might not work.
Bingo:
for item in self.collectionView!.visibleCells() as [UICollectionViewCell] {
var indexpath : NSIndexPath = self.collectionView!.indexPathForCell(item as CollectionViewCell)!
var cell : CollectionViewCell = self.collectionView!.cellForItemAtIndexPath(indexpath) as CollectionViewCell
//access cell data
println(cell.labelName.text)
}
found here