How to change section headers in iOS? - objective-c

Bit of background of the app I'm currently writing. It's a tableview and when a cell is tapped it loads a local HTML page.
However, now I'd like to implement section headers, a section header for complete and incomplete. The default header would be incomplete and after an interaction on the table view by a user, the cell is moved to complete. An option would be required to reverse the change should the change be done by mistake.
My first thought was to put in a check box in each cell, checking the box would move the cell and unchecking would move it back but I see iOS offers no such function, instead using switches instead.
For my needs, switches wouldn't work very well. So I'd like to ask others thoughts on this and how to implement such a thing, if anything.
Any thoughts or help appreciated.
Thanks.

You can implement a check mark using this approach. Basically you need to add a button on the cell and change its background image to show selected and deselected state. You can also consider using the default accessory check mark feature in tableview cell.
For eg:-
cell.accessoryType = UITableViewCellAccessoryCheckmark;
and
cell.accessoryType = UITableViewCellAccessoryNone;
In order to implement the section header, you can use - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method or viewForHeaderInSection: method.
You can move a cell from one section to another one using the below method,
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

Related

Rounded UITableView with thin edges like FaceTime app

How i can create tableview like this?
(separators merges with edges and edges is rounded)
This was out of the box in system version below 7.0. If you want something similar, you can make custom graphic for the first and last cell. In UITableViewDataSource you have got a method, which helps you to control cell's content.
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
From indexPath.row you can get cell number to know if it is first or last cell in the section. And you can set your custom cell look.
You can simply add UITextfields without background [UIColor clearColor] and put a background image to your login cell
If you would like to use table view with rounded corner you should go with QuartzCore framework by importing
#import <QuartzCore/QuartzCore.h>
then
in your method from where you create table view use following code -
yourTableView.layer.masksToBounds = TRUE;
yourTableView.layer.cornerRadius = 10.0f; // as per you requirement please give this value.
you can take any number of rows. but table corners remains as it is.
I think this will help you....

What to do when change in one UITableViewCell affect how other cell works?

Say I choose to follow or bookmark a catalog. All catalogs that share the same parent will be bookmarked too.
After a call to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath things will sort of fixed.
The thing is cellForRowAtIndexPath is not called until the visible cells become unvisible and then visible again.
How do I make visible Cells to refresh again?
If I understand you right, you simply call [tableView reloadData];. This will display the actual data model.
Use visibleCells and indexPathsForVisibleRows properties of UITableView. You will need a method to refresh the cell from the underlying data model.

How to make a click on TableViewCell open a new view and keep data?

So I've added a UITableView in a UIViewController. I also subclassed its TableViewCells to look like this :
Now I just want to know how I can click on the cells to open a new view with another TableView containing a selection of options, and to write the selected option instead of the "This is row : %d" line. (everything is embedded in a NavigationController)
Thanks a lot for your help.
You can use UItableview Delegate
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
You will get click event. In that you can use indexPath.row for retriving string from your data source array (which contains data you shown in cell.) on which user has clicked. Now you can open (push)new view controller using navigation.
Pass the indexPath.row or particular string to your next view controller so that you can get which one is get selected.

Is there any difference between UITableViewCellAccessoryDetailDisclosureButton and UITableViewCellAccessoryDisclosureIndicator

I have created a method - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
for UITableViewCellAccessoryDetailDisclosureButton.
Now I want to use UITableViewCellAccessoryDisclosureIndicator in place of UITableViewCellAccessoryDetailDisclosureButton.
Is there any difference between UITableViewCellAccessoryDetailDisclosureButton and UITableViewCellAccessoryDetailDisclosureButton?
Apple HIG suggests that you use UITableViewCellAccessoryDisclosureIndicator to navigate through hierarchical data, and UITableViewCellAccessoryDetailDisclosureButton to perform some action, possible bringing up an edit view, that may change the data. However, most programmers seem to ignore this.
You can implement the delegate method tableView:didSelectRowAtIndexPath: like this:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
Or vice versa.
There is difference. UITableViewCellAccessoryDetailDisclosureButton is actually a button but UITableViewCellAccessoryDisclosureIndicator is not.
You can use UITableViewCellAccessoryDisclosureIndicator instead of UITableViewCellAccessoryDetailDisclosureButton but you can not get the tableView:accessoryButtonTappedForRowWithIndexPath: method called when you tap on the UITableViewCellAccessoryDisclosureIndicator as it is not a button.
Yes, they're different.
Use UITableViewCellAccessoryDetailDisclosureButton when the user tapping the blue button performs a different action than tapping the rest of the row, even if the rest of the row does nothing.
Use UITableViewCellAccessoryDisclosureIndicator when the entire row is tappable and produces the same action.
If your behaviour is something else, use some other mechanism.

swipe to delete when already in edit mode

I have an iphone app using a uitableview where I'd like the "reorder" controls to always be displayed, and have the user swipe to delete rows.
The approach I'm currently taking is to put the tableview in edit mode and allow selection in edit mode
self.tableView.editing = YES;
self.tableView.allowsSelectionDuringEditing = YES;
I then hide the red delete circles using
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
I cant figure out how to get the swipe gesture to bring up the "delete" on the right side when the tableview is already in edit mode, can somebody point me in the right direction?
alternatively, if someone knows how to get the cell reordering controls to show when NOT in edit mode, that would also be a workable solution
cheers
When the user swipes on a given row, you need to store a reference somewhere so that you can change the value returned by editingStyleForRowAtIndexPath and shouldIndentWhileEditingRowAtIndexPath. Your best bet is likely to use indexPathForCell on the cell that is swiped and store that. Then in the two display methods above you need to check if the NSIndexPath is the same or not (I'm not sure if they will be the same pointer or if you'll need to compare the section/row values - testing required). If they match, display the delete button.
Note that you may need to call reloadData on your tableView to have the effect appear without scrolling away and back again.
I'm wondering if the way you're headed now would break the Human Interface guidelines, which would result in the app not getting approved.
I can't see why you can't capture the swipe gesture and then use that to 'unhide' the red delete (stop sign) icons for the delete confirmation?