How to remove editinng mode by touching on tableview? - iphone

If you click on the Edit button, you see the red stop signs. How to remove this when user touch on the tableview or tableview cell?
Please help me for this
Thanks in advance

Use setEditing method of UITableView.
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
Like below
[myTableView setEditing:NO animated:YES];

If you want to stop editing on cell selection then use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[myTableView setEditing:NO animated:YES];
}

Related

How to Hide UITableView?

When pressing a button in my view controller it shows a UIView which has UISearchBar and UISearchDisplayController and UITableView in it(changes the view's hidden property to NO).
When I select a row in the table view I set the view's property to hidden=YES, but it doesn't hide the tableView. What can be the problem?
I implemented the UITableViewDelegate protocol and I receive tableView:didSelectRowAtIndexPath: message(I set the view's hidden=YES there).
Please note that when I call view's hidden=YES from searchBarCancelButtonClicked: it hides successfully.
I think that UISearchDisplayController is causing the problem.
Some code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.searchView.hidden = YES; // hide successfully the tableView.
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.searchView.hidden = YES; //doesn't hide the tableView.
}
EDIT: Found the problem, see my answer below. In short I added [self.searchDisplayController setActive:NO];
Found the problem - I needed to add [self.searchDisplayController setActive:NO]; and now it works.
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.searchDisplayController setActive:NO]; //Added line of code.
self.searchView.hidden = YES; // Now it works!
}
Try this:
tableview.hidden = YES;
[self.yourview setHidden:Yes];
if the tableview is inside the view it should also hide

Select TableRow and SelectionColor should be visible and then go off automatically

What I was trying - I have a UITableView. On selecting any particular row it should show a selectionColor(Blue etc) and then it should disappear. Any property/code to do this? I am actually applying in in MyCalender view.
You can use [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
in your - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method.
You should refer the delegates and datasource in tableview for this
The datasource sets the inputs to table
The delegate gives you callbacks of actions on the tableview .
So write the delegate methods ,include it in classdef UITableViewDelegate,connect it in xib
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This delegate method is invoked if you click on a particular row.The particular row is the row at the "indexpath"
finally include this line which deselect the code
[tableView deselectRowAtIndexPath:indexPath animated:YES];
add this to your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
`
UIView *violetColor = [[[UIView alloc] init] autorelease];
//violetColor.backgroundColor = [UIColor colorWithRed:0.824 green:0.749 blue:0.553 alpha:0.70];
violetColor.backgroundColor = [UIColor colorWithRed:0.724 green:0.749 blue:0.953 alpha:0.70];
cell.selectedBackgroundView = violetColor;
`
and then add this to your didselect `
if (indexPath != nil) {
[mTableView deselectRowAtIndexPath:indexPath animated:YES];
}
`.i hope this will do the trick.
In delegate method didSelectRowAtndexPath use this code
[tableView deselectRowAtIndexPath:indexPath animated:YES];
If you are using UITableView and want to remove selection of the UITableViewCell. Then you have to use the below code to deselect tableview cell.
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];

UITableCell - How do I turn off the selected state of the cell when user navigates back to view?

I think this is a very common situation, but I can't find how everybody else solves the problem.
I have a UITableView, and when a user taps a cell I push a new view controller (using UINavigationController) on the stack. When the user taps "Back" on the navigation bar, the cell still appears in selected state (i.e. blue background).
I want the background to be blue initially, when the user tapped the cell, but to be turned off when the page is shown again.
you could deselect the cell before or after you have pushed the new viewcontroller.
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[aTableView deselectRowAtIndexPath:indexPath animated:YES];
// create and push new viewController
}
There are two ways you can do the same thing:
Either Reload the whole Table in View will Appear
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[YourTableView reloadData];
}
OR Either
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[YourTableView deselectRowAtIndexPath:indexPath animated:YES];
}
Looking at performance wise second one is best solution to use.

Table View scroll when text field begin editing iphone

I have table view controller in iphone application. Table view has two sections. First section has two rows and second section has one row. Second section has a custom table view cell.
Second section has a textfield which hides when text field begin editing and keyboard pops up. I want this table view to scroll when keyboard pops up.
I tried the following code which I came across on different websites but in vain.
Thanks in advance.
-(void) textFieldDidBeginEditing:(UITextField *)textField {
CGRect textFieldRect = [textField frame];
[self.tableView scrollRectToVisible:textFieldRect animated:YES];
}
atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
-(void) textFieldDidBeginEditing:(UITextField *)textField {
UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
[self.tableView scrollToRowAtIndexPath:[tableView indexPathForCell:cell]
atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
I have run into this on Static Cell TVC's. There is an issue when overriding viewWillAppear and NOT calling its Super. So if you are doing that, make sure to call
[super viewWillAppear:animated];
at the top of viewWillAppear
You want to use the setContentOffset method of the table view. Determine the magnitude of the vertical scroll (in pixels), and then:
CGFloat verticalScroll = ... your code here ...
[self.tableView setContentOffset:CGPointMake(0, verticalScroll) animated:YES];
My problem was I was adding the table cell containing the UITextField in the
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
function. If you do this the automatic UITableView scrolling doesn't work.
So, you have to do some arithmetic to work out when your last row is showing and put your special UITableViewCell in here along with all the others.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

How can I hide the UITableView that UISearchBar created?

In my iPhone application I have a search bar and search display controller. When the user types something in the search box, the table view loads and is now visible. When a user clicks on a row, I would like to get rid of the tableView and go back to the view where the user originally clicked the search bar. I have searched all over the documentation, I cannot find how to do this anywhere. I have tried [tableView setHidden:YES]; but when the user clicks on the search bar again the tableView never returns.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
Please can someone point me in the right direction.
you can try smth like
[mySerchDisplayController setActive:NO animated:YES];
Why don't you just remove the table view from the View Hierarchy?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// update your model based on the current selection
[tableView removeFromSuperview];
}