iPhone Can't deselect a UITableViewCell - iphone

I have a RootViewController class which is inherited from UITableViewController.
When a cell is deselected by the user I want to enable/disable certain buttons on the toolbar.
How do I trap the deselect event?
-(void)tableView:(UITableView *)tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
{
if(indexPath.row <= rowNumber)
{
[viewButtton setEnabled:NO];
[editButtton setEnabled:NO];
}
}
I tried using this method but it doesn't seem to execute at all. Any ideas how cam this be done?

I do not think there is a deselectRowAtIndexPath event, there is a method that you can call to deselect the indexPath, but looking at the SDK I do not see an event for this in the UITableViewDelegate: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html.
Could you enable/disable certain buttons on the toolbar during the didSelectRowAtIndexPath: event?
-Rog

This is in the current beta SDK only which means it could be buggy / changed / unsupported...
I did noticed that your method declaration doesn't match the SDK (at least, the version I have).
Try removing animated:(BOOL)animated; I don't think it's applicable here.
See line ~345 in UITableView.h, and/or right click on didDeselectRowAtIndexPath and "Jump to Definition", where you'll probably find how the delegate method should be defined.
That said, if your goal is simply to "enable/disable certain buttons when a cell is selected",
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
should work just fine. This will occur after they select the cell and before it's deselected. 'deselect' has to do more with animation than user interaction. The only reason I can think you would want to use deselect is maybe the aesthetic value of ensuring your event only occurs after the select cell is no no longer highlighted.

Related

Swipe to delete cell with strange behavior

I have an application where the main root is a UIViewController with a similar behavior like the application of facebook or path, that is, swipe and show another view, on the left or right.
However, my problem is that sometimes the main UIViewController has UITableViewcells, which should be eliminated with swipe, yet this does not work correctly, sometimes it detects the gesture sometimes not.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataItems removeObjectAtIndex:indexPath.row];
[self.tableView reloadData];
}
}
I am adopting this library
enter link description here
to make the controller of the UIViewController's
Any idea how to solve this?
Thanks in advance.
The problem is the gesture you're using. If both the table cells and view are trying to intercept swipe events you are guaranteed to not get the behavior you're looking for. The way that I usually solve this problem is to make a button that changes the table into editing mode. That way you don't have a conflict.
[tableView setEditing:YES animated:YES];
The problem isn't program design or language capabilities, it's having the EXACT SAME gesture do two DIFFERENT things. This isn't physically possible to implement and always get what you want. iOS devices can't read minds, although I heard about a new API in iOS 7...
You could try using multi-finger gestures.

is there any if statement for showing/hiding a method in objC?

i use same uiviewcontroller's instance in different tabs.
there is a uitableview in viewcontroller.
in firstviewController instance, i dont wanna edit the uitableview.
in the second one i use edit mode for tableview.
thats why i want to show or hide this method:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
is it possible to make an if statement like this:
#if (editingOK)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
....some codes
}
#endif
editing OK is a BOOL property.
if you ask why i want it, because if the user swipes on the cell, it display Delete button.
i just want it if my editingOK=YES.
The #if/#endif syntax is used for conditional compilation: it lets you modify your program at compile time based on build configuration. Read about the "C preprocessor" to learn more.
If you are, as you say, using the same object instance as the delegate of different UITableViews, you must have some way to determine which table you are dealing with.
What you need to do is implement an additional method:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
That method is called when the user swipes the cell, and you can decide if a delete button should appear or not, then return the appropriate UITableViewCellEditingStyle constant.
Isn't editability controlled by calling the setEditing method of the UITableViewController? So you could set that depending on whether or not you want to enable editing, w/o this #ifdef ugliness.

UITableViewController not highlighting cell when it's selected

Hi
I've got simple question which I don't know how to answer.
In my app I've got UITableViewController with cells. When I select one item (cell) it's getting higlighted and in other thread I'm loading chunk of data to display to the user (after load is done new VC is pushed). When doing it with thread user still can interact with application like, going back to other NavController and I do want that to happen. What I don't want to happen is that when loading isn't complete user can select other cell in table and it get's highlted. How I can prevent that (only highlit, I'm checking if there was a previous request so I'm not putting another thread untli previous request is done).
So basicly my question is, how can you foribd user from interacting with table view controller?
Set the selectionStyle of the UITableViewCell's to UITableViewCellSelectionStyleNone.
You can use the following to check if row can be selected:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (rowSelected) {
return nil;
}
return indexPath;
}
So, you only select it if no row is selected. In your didSelectRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
rowSelected = YES;
// call method that is going to do something and mark rowSelected = NO;
}
You can deselect the row by using
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];
There is a risk that your users will be confused. A highlight is not enough. There should be very clear visual feedback that a network opperation is ongoing and that different rules apply.
either push the details view immediately after the user selected a row and show an activity indicator in there.
or give the whole table view a different look while loading data for the selected row: e.g. Show activity indicator in the selected row & hide the disclosure chevrons in all the other. While doing that, you can set the selection style to 'none'

How to enable void "didSelectRowAtIndexPath" and disable it?

I search didSelectRowAtIndexPath this key word
And found most problem is how to trigger it
But my question is how to enable it with another conditions
You can check my last question here - How to add a radio button in tableview
how To disable this void when the radio button is not selected ???
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
I'm a bit confused by your question, but from what I can tell, you want to prevent a tableView row from being selected under certain conditions? For that you'll want to use tableView:willSelectRowAtIndexPath:. If you return nil from that method the tableView will not select a row. You may find it helpful to read the documentation for UITableViewDelegate.
Well I guess you need to run the code within the method conditionally. If your radiobutton is enabled, just run it, if not, return nil (or the other way round). You cannot prevent the method from being called at all, however.
according to your radio button state set the cell property
cell.userInteractionEnabled = NO;

iphone sdk - select a cell in a tableview, with code

I would like to select a cell in a tableview, except with code before any user interaction.
Is this at all possible, a quick search through the sdk notes doesnt yield anything. Where should I look?
Regards
UITableView class, "Managing Selections" section.
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition