UISearchBar Staying at top when seguing from tableview results - ios

I created a search with 2 UINavigationcontrollers and with 2 UITableViewControllers. One for displaying the initial results, and then another TableViewController for when displaying searched results.
This is where i think the issue occurs. I use this method to show the resultsTableViewController where i make it the top view controller.
Now when i segue from the results view controller, the UISearchBar stays on top. When i code [vc.tableView setDelegate: self];.
it removes the issue of the search bar staying but then screws up the didselectrowatindex path which i need to identify because the results aren't the same from the original and the results Tableviewcontroller.
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
// Set searchString equal to what's typed into the searchbar
NSString *searchString = self.searchController.searchBar.text;
[self updateFilteredContentForAirlineName:searchString];
// If searchResultsController
if (self.searchController.searchResultsController) {
UINavigationController *navController = (UINavigationController *)self.searchController.searchResultsController;
// Present SearchResultsTableViewController as the topViewController
SearchResultsTableViewController *vc = (SearchResultsTableViewController *)navController.topViewController;
// Update searchResults
vc.searchResults = self.searchResults;
// And reload the tableView with the new data
[vc.tableView reloadData];
}
}
Here's a project i mocked up that has the issue included.
http://expirebox.com/download/10533c5d386618b95bb39bd1dc886ace.html

try to extend your next viewcontroller to class.so i will create new data class and extend to viewcontroller than paste this code in didSelectRowAtIndexPath: method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
data *next=[self.storyboard instantiateViewControllerWithIdentifier:#"datascreen"];
[self presentViewController:next animated:YES completion:nil];
}
ok bro try this
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
data *next=[self.storyboard instantiateViewControllerWithIdentifier:#"datascreen"];
[self.navigationController next animated:YES];
}
both class use this code.try this if any problem than tell me

Related

ios - naming and make action from each cell

So I'm using this code... "MFSideMenuDemoStoryboard"
https://github.com/mikefrederick/MFSideMenu/tree/master/Demos/MFSideMenuDemoStoryboard/MFSideMenuDemoStoryboard
And I want to give a name to each cell in the "SideMenuViewController.m" and make each one of these cells show a specific UIView in the "DemoViewController.m". any help with that ?
any help is appreciated, thank you!!
In SideMenuController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DemoViewController *demoController = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
demoController.title = [NSString stringWithFormat:#"Demo #%d-%d", indexPath.section, indexPath.row];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
NSArray *controllers = [NSArray arrayWithObject:demoController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
Replace this code with something like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//EDIT #1
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
DemoViewController *currentCenterView = [[navigationController viewControllers] firstObject];
[currentCenterView addAnotherView:indexPath.row]; //This is where you will tell your 'middle view' to load another UIView ... You can use the indexPath.row to determine which option was tapped and act accordingly.
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
You obviously need to add a method - (void) addAnotherView:(NSInteger ) row; to your DemoViewController or whatever you've called it.
Edit #1 this will reference the current loaded view. This will only work if you are only using 1 view controller on the navigation controller stack. Otherwise grabbing the first object won't work and you'll need to search for the right index.

Flip Transition from a Tableview Custom Cell to a UIViewController

I created a custom tableview cell that gets displayed in my tableview. Upon user tapping the cell, I would like to create a flip horizontal transition to a new view controller. How to do this either using Core Animation or UIView?
Sorry I am a newbie can't find the right way to do it anywhere.
Thank you in advance.
I guess You are talking about this.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create the next view controller.
DetailViewController *detail= [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[detail setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:detail animated:YES completion:nil];
}
For Dismiss:
-(IBAction)close:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
write this method in DetailViewController and call this method to back.

How to present modal view in "parentViewController"?

I'm trying to write iPad app.
I have UIViewController as parentViewController (full screen) for masterView and detailView (my handmade splitView). Also I have a separate view (for example moreDetailView) with class and xib, which I would like to show as modal.
masterView has UITableView and detailView has UICollectionView. Both of them has own classes and xib. In detailView there are several items.
In my didSelectItemAtIndexPath: of detailView I would like to show moreDetailView.
So, how can I do that? And how to show it in parentViewController, but NOT in detailView.
Hope my question is understandable.
The code below will present your controller in a modal formsheet (you can change this with the setModalPresentationStyle) on the top of your splitView.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}]; }
You are initializing your masterview and detailview in parentview. To access the parentcontroller you can declare a property in detailcontroller as
UIViewController *parent;
and while initializing you can do
detailController.parent=self;
and while showing modal you can do
[parent presentModal]; //instead of [self presentModal];
I hope above works for you, you will need to correct the syntax though.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}];
}

IOS - get a value from a table view controller and send it to another table view controller

I have two Table View Controller in a Navigation Controller. The Cloth table is the main view and when I click on one of the cells go to another view controller that gives me the detail, when I select the option i want and return to the Return of the Navigation button, I lose the information. How do I take the value to the main view?
Here my code: Main View - AddClothViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[list objectAtIndex:indexPath.row] isEqual:#"Categorias"] )
{
CategoriesViewController *DVC = [[CategoriesViewController alloc] initWithNibName:#"CategoriesViewController" bundle:nil];
[self.navigationController pushViewController:DVC animated:YES];
}
}
Here my code: Categories ViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set the checkmark accessory for the selected row.
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
// This is my main View Controller when i declare a variable category and I try to access from
//here
AddClothViewController *DVC = [[AddClothViewController alloc] initWithNibName:#"AddClothViewController" bundle:nil];
DVC.clothNew.categoria = [list objectAtIndex:indexPath.row ];
}
I resolved my problem by using this tutorial.
(Simple delegate tutorial for ios development)

Pushing a view in Storyboard

I am trying to use Table Views and navigation controllers. This is the code I would use if I was using NIB files. This piece of code would work fine if I was using NIB files, but I decided to try storyboard -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
}
I have created another scene in storyboard and have everything set up out there. When a user clicks a cell in this Table View they will be taken to that scene. This is what I wrote for the code but it is not right and I'm hopelessly stuck :( -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"articleView"]){
UINavigationController *navigationController = segue.destinationViewController;
WebViewController *controller = (WebViewController *)navigationController.topViewController;
controller.webView = self;
}
Answer - Answers 2 and 3 are both right
I had a very similar problem 2 days ago, with the user selecting the disclosure accessory on a row and wanting to invoke a segue. What worked for me:
In storyboard, create segue "articleView" from the entire tableView controller (not the cell) to the next viewController.
Add the following method to your tableViewController:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"articleView" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}
Just for you I also tested with tableView:didSelectRowAtIndexPath: and it works.
Enjoy,
Damien
If your table view is already embedded in a navigation controller (looks that way, from your first code snippet) then the destination view controller of your segue will be a WebViewController, not a navigation controller.
You can therefore have your prepareForSegue method pass the item directly across :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"articleView"])
{
WebViewController *controller = (WebViewController *)segue.destinationViewController;
RSSEntry *entry = [_allEntries objectAtIndex:[self.tableView indexPathForSelectedRow].row];
controller.entry = entry;
}
}
You may find this excellent two-part tutorial helpful
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Resources