I am creating a basic checklist app and would like to know how to make a cell display a simple checkmark once it is touched. I have used no coding up to this point and have done everything in storyboarding. I have a single view that contains 10 cells. Each cell is a "task". I would like to display a checkmark on each cell as it is clicked. I know some basic objective-c but am not advanced.
the clue is within the accessory of a table cell, you should use something like
cell.accessoryType = myCheckBoolean ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
So you should use a tableview and setup your handling according to selection events or anything else in your existing code and use the above snippet to display the check mark. (Image could not be posted)
Related
I am working on a app which includes table cells. I want that when i swipe table cell it shows two options, first about that cell value and another for delete that value. How can i show that in a way that the cell value shows in half of cell and the options show in half of cell.
Thanks in advance.
There are an out of the box solution, called HHPanningTableViewCell. It does exactly what you need!
HHPanningTableViewCell is a UITableViewCell implementing "swipe to reveal" a drawer view. Such a view typically holds action buttons applying to the current row.
This library, SWTableViewCell, should help you:
https://github.com/CEWendel/SWTableViewCell
An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail Application)
You have to create a custom cell and override Apple's behavior which is swipe left to delete and then show your options. You can add gesture recognizer to the cell and on swipe to left animate the cell content view and animate in your option view or however you like it to be. I can write up an example code if you need.
I need a way of setting the UITableViewCellAccessory for any row. However the catch is that I need to be able to do it OUTSIDE of the UITableView delegate methods.
I have tried this, but it doesn't show up the accessory.
[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:1]] setAccessoryType:UITableViewCellAccessoryCheckmark];
If it makes any difference I created the UITableView in IB in a storyboard. The data is static, and I'm using a grouped table style with only one section.
Please can someone help me out?
If your table view is scrolled so the cell in question may sometimes scroll out of view and then back into view, you should manage the content of that cell only from within the UITableView method cellForRowAtIndexPath:. The reason is that when cells are redrawn, the tableview object calls this method to make sure that visible cells are properly rendered. (Cell that are not visible don't need to be rendered at all.)
That being said, this is where you should handle the cell content, even if the table view doesn't scroll the cell in question out of view. It wil lmake you life a lot easier if you follow this design pattern when working with table views.
Inside that method, you can test (using if statement, for example) the value of the indexPath.section and indexPath.row so that you can configure the specific cell the way you want it. This includes putting in the accessory.
Always use [NSIndexPath indexPathForRow:inSection:] when working with table views.
You can figure out what indexPath you need the checkmark on and then use something like this
UITableViewCell * cell = [tableView cellForRowAtIndexPath:someIndexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
I have a UITableView that I have scroll to the bottom as soon as the user adds another element/table cell to it. For the screen this works fine, because the user can see the cell they just added at the bottom of the table. But when running my app using VoiceOver, the first UITableCell to get focused and read is the top cell that's visible on the screen.
I want to set it so that the cell that gets focused and then read as soon as this UITableView appears is the very last cell in the table. How do I do this? It seems like it would be very simple but I can't figure it out.
Here's what I tried so far (in cellForRowAtIndexPath):
if (cellJustAdded && indexPath.row == [array count]-1) {
cell.accessibilityElementIsFocused = YES; //obviously this does not work
}
but I don't think you can use accessibilityElementIsFocused like that.
When you want VoiceOver to select a certain element you can post an accessibility notification using UIAccessibilityPostNotification( ... );.
Depending on if it's a major (complete screen) change or a minor (layout only) change you should post either
UIAccessibilityScreenChangedNotification (complete change)
UIAccessibilityLayoutChangedNotification (small change)
In both cases the optional argument is the element that VoiceOver should move to.
So after having added the new cell to your table view you would call
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
yourNewCellThatShouldHaveFocus);
I created list of todos. Now I want to put the checkbox for each one cell. When I mark it as checked, it can be marked and then we select delete button if we want, which is also in the same cell at right side and deleted, but I am not able to perform action like this.
Can anyone please help me?
#Chakradhar not a big issue you can do it very easily with or without using custom images.
In your didSelectRowAtIndexPath delegate try to check and set the UITableViewCellAccessory as per your condition.
This is the way in which there is no need to use extra images and you can checked for you particular selected cell:
if (//here you check)
{ // item needed - display checkmark
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{ // not needed no checkmark
cell.accessoryType = UITableViewCellAccessoryNone;
}
Take this shopping tutorial and see didSelectRowAtIndexPath delegate method see how they had used the condition.
Edited as per your last comment: For custom accessory view look for Implement a Custom Accessory View For UITableView in iPhone
Good Luck!
Use this
cell.accessoryType = UITableViewCellAccessoryCheckmark;
You can actually add custom button with an unchecked image on your cell. On button action method you can change the image to checked & handle rest of the things you want to handle.
In my iPhone application I have used (UITableViewCellAccessoryCheckmark) to add the checkmarks in the cells, - it is added to the cell at the right side of the cell.
I want the checkmarks to display in the middle of the cell and after that a string should display. So that the user can set the cell item as checked or unchecked.
Please provide any solution or any code for adding the (UITableViewCellAccessoryCheckmark) in the middle of the cell.
There is no built in way to do this. You will have to create a cell, then in tableView:cellForRowAtIndexPath: you will need to either add a custom subview, or return a custom cell and tell it to display the custom checkmark you added based on the data state.
The accessory view of the cell is always on the right side, outside of the cell's content view (see the Table View Programming Guide for more on this). If you want to do something like this, you really need to create your own cell class, and draw the checks yourself.
Speaking as a user, this design seems sort of confusing, and definitely not what I'd expect. What's the string you're displaying to the right of the check? Maybe something like the UITableViewCellStyleValue1 style cell would work, instead? (See Standard Styles for Table-View Cells for more.)