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.
Related
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"
}
I'd like to add view beside tableviewcell when user click table view cell.
before user click
---cell1---
---cell2---
after user clicked
---cell1---
---detailview---
---cell2---
How to do that?
If you are looking for something like another view appearing below the tapped cell and not an expanding tapped cell,you can insert a tableview cell just after the tapped cell.Use insertRowsAtIndexPaths and insert the cell.You can create this cell as a custom cell.
There is 2 options to do that:
- To make detailView as another cell, just insert below the cell user clicks
- Cell add the detailView initially. And make a switch to show it or hide it.Just because cell in table view is reused, we should not add subview in a cell already in table view, which will cause some problem in reusing.
There is CustomCell in tableviewcontroller .And in which there is dynamic txtfield. which is viewed by tag value. I am saving textfield value on dictionary on "textFieldShouldEndEditing". I want to save textfield value on button (Textfied is dynamic,no outlet is created for textfield).
First Image attached
I want to edit the saved address. Second Image attached
kindly revert asap
If i understood your question properly then,
You need to set the button (Which i guess is also inside the custom cell), same tag as that of the indexpath of the cell.
By that you can get the indexPath of the cell and get the cell by
MyCustomCell *cell = [self.tableview cellForRowAtIndexPath:button.tag]
Then, you can get the textfield inside the cell also by just calling cell.textFieldName.text, and you will get the text.
For more clarity the IBAction method of the button, should be something like this.
-(IBAction)buttonClickedToSaveTexd:(id)sender{
UIButton *btnOfCertainCell = (UIButton*)sender;
MyCustomCellClass *currentCell = [self.tableView cellForRowAtIndexPath:btnOfCertainCell.tag];
NSString *textOfTheCell = currentCell.textFieldName.text;
}
Again, for this to work, in cellForRowAtIndexPath you need to assign the button tag as indexPath.row. You dont need to set tag of the textfield.
I have a tableview and each cell has a switch as accessory view. I can iterate through all cells to see which ones have switch on.
I can easily change the accessory view to be a check mark.
I need to implement that tapping each cell toggles between checkmark and none.
Then in touchupinside, iterate through all cells to see which ones are checked and which ones are not checked.
I have implemented to check for Switch state
var indexPaths = table.IndexPathsForVisibleRows;
foreach (var indexPath in indexPaths)
{
var cell = table.CellAt (indexPath);
var switchView = cell.AccessoryView as UISwitch;
if (switchView.On)
{
/*code to handle switch on*/
}
}
I dont know how to have similar code to check if accessoryview is Checkmark and if it is set to none
Here's an example that uses MarkupKit's LMTableView class to implement selection management:
http://gkbrown.org/2015/08/10/using-lmtableview-to-implement-radio-button-like-behavior-in-ios-applications/
Essentially, you define a particular section of a table view as being either single-select or multi-select, and the LMTableView class manages the selection state for you. You can then query the table view to find out which rows are selected, or you can respond to selection events yourself via table view delegate methods.
I have a TableView with custom cell with a CheckBox, A label and a TextField. I want to get label text and TextField text of all the cells that I have CheckBox checked. How can I achieve it. whenever I scroll the TableViewCell index changed so I am not able to use rowAtIndexPath.
From my point of view, you will have to use array to keep track of which cells are checked. So declare NSMutableArray *checkedCells; variable and initialize it. In your didSelectRowAtIndexPath write following lines :
UITableViewCell *cell= [tableView cellForRowAtIndexPath:indexPath];
if (cell.radioChecked)
{
/*Create a object with textField and label value here.and add that object in checkedCells here*/
}
else
{
/*remove regarding cell object from checkedCells here*/
}
This way you will get properties of cells which are checked.