Trying to update UIView from UITableView selected cell in sliding menu - iphone

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
}

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

when I click a UIButton I'm trying to find out which cells are currently selected inside a UITableView

I have 2 UITableViews. When I click the UIButton outside of either UITableView I'm trying to determine which cells are selected in each tableview.
Anyone have a good way of doing this? Would I loop over the cells to determine which cell is currently selected? Or is there already a method that can tell me?
Thanks a bunch!
You can use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
Take a look at UITableViewDelegate Protocol Reference
UITableViewDelege Reference
EDIT: When the user select a row in one of your tables you can get it using this method and a couple of variables for the table and the cell and then you can pass what you got as soon as the user tap on your button.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
thisIsMyTable = tableView;
thisIsTheSelectedRow = indexPath.row;
}
- (void)buttonTapped {
// Do what you need
}

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.

reload TableView with data

Basically i have a view with just a table view on it and on another tab you can add to this table view. but when you click the tab with the table view in it isnt updating it self, so how would i reload the data in the table view i have tried :
- (void) viewWillAppear: (BOOL) animated
{
[ThirdViewController.tableView reloadData];
}
with no success as i get error Expected ':' before '.' token.
all of the cells are added via
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Any help would be great
Looks like ThirdViewController is the name of a class, not an object.
Try just
[tableView reloadData];
You can modify your app in the following way
1 Take a segmentation control above the table view.
2 When the user taps on any of the segment,take separate View Controller which is pushed onto the stack.
Cheers

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