How to Hide UITableView? - iphone

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

Related

Trying to update UIView from UITableView selected cell in sliding menu

Been working on this one for a while and am stuck. I have a sliding menu in my app that is a UITableView and what I'd like to happen is that when a cell is selected the topView will be updated to a UINavigationController that loads my UICollectionView. I am using storyboards and currently I have a cross fading modal segue to load the new view for functionality purposes. Here is a screenshot and any help would be greatly appreciated. I know the view should be updated in the function
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
The top UIView is called topLayer
Screenshot available here: http://d.pr/i/idRo
connect a manual triggered segue from topview to UINavigationController and give it an identifier. use that identifier as below:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
[self performSegueWithIdentifier:#"topviewToNagivgationController" sender:self];
}
//else
}

How to remove editinng mode by touching on tableview?

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];
}

iPhone, how do I disable / enable a nav button based on table view row selection?

I want to only have my navigation bar select button enabled when a row in my table view is selected.
How ?
Use the enabled property on UIBarItem (superclass of UIBarButtonItem) to enable/disable it in your table view's delegate's tableView:didSelectRowAtIndexPath: and tableView:didDeselectRowAtIndexPath: methods.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.navigationItem.rightBarButtonItem.enabled = YES;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
self.navigationItem.rightBarButtonItem.enabled = NO;
}

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 {

tableview crashed when press back button of navigation controller?

the numberOfRowsInSection returns 0 when i press navigationcontroller's back button,
but - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is called when i put break point...application crashes ..any help please?
you should set the delegate of tableview to nil, dealloc before releasing your table view like this:
- (void)dealloc{
[myTableView setDelegate:nil];
[myTableView release];
myTableView = nil;
}
besides are you trying to reload the table in viewWillDisappear, if yes you should avoid it and find a workaround for this.
Hope this helps.
Try to make the numberOfRowsInSection method return 1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}