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.
Related
What I want is for the buttons to look like this:
I just added my buttons from interface builder and connected them to the code. Does anyone know how to do this? And is it possible to do this with a UITextField object?
You'll want to use a UITableViewController with the sections set to be UITableViewStyleGrouped. Unless if you can find a background for each button, this is what the settings app uses.
To make a UITableView:
Each of the groups is a section, so you'll want to return how many sections you have with -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView.
For every section, you want to say how many rows there are with - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section.
You'll want to customize each cell with - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath (which, by the way, tells you which section's particular row you're modifying in the indexPath variable).
You'll want to handle the row click in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. The the code below helps you deselect the table view. :[self.navigationController pushViewController:detailViewController animated:YES];
also use - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender to handle what happens after tapping a specific row.
Tutorial that really explains this stuff in detail: http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/
Apple Documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
For the UITextField, you can set this to Grouped in the Interface Builder or pragrammagitaly to this: UITextBorderStyleRoundedRect
Good Luck!
If the standard UIButton is not sufficient, then create your own View:
You create an UIView class and in drawRect method you
draw a path consisting of 4 arc with 90° (corners) and connect that with CGPathLineTo.
Use corner radius, width and height as paramter.
Further tipps:
use CGTransformMakeScale such that you rectangle is transformed to a squre with side length 1. This simplifies the calculation of the arc parameter.
Dont forget to tranform the corner radius, too (e.g with scale.x)
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
First of all, I know this question has already been asked but the answer did not solve my problem.
So, Im in XCode 4.2. I am loading a table View and trying to select a row. The row does not seem to be selected. I also tried NSlogging in the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}
but the method is not called at all. Also, the table does not bounce.
FYI, I have set the bounce and selection properties in IB.
Can someone please help me out?
Thank You!
Did you set the delegate of your table view to whichever class has didSelectRowAtIndexPath defined, something like:
sometableview.delegate = self;
I'm flummoxed as to what I may have done to cause this, but it seems that the lines that represent (and allow) MOVING of a UITableViewCell have disappeared when I enter edit mode. The delete button is there.
Anyone know what method or methods control that (usually default) cell accessory from being displayed when a user enters edit mode?
Thanks!
Turns out I was missing this method:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{
}
Thank you, Git!
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?