UISearchBar and segues - objective-c

Im using UITableViewController to manage data. When I click on the cell my program goes to another scene (let it be myDetailViewController). But i just added search bar (UISearchViewController) and search works great but when I click on the cell from the table with the filtered data nothing happens. But I need the program to go to myDetailViewController scene to view object details. How can i perform it?
Btw, for changing views (from a basic cells, not filtered) I'm using segues. And I'm also using this method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"nameofmysegue"]) {
//some code to give some data to new controller;
}
}
And when I'm using
tableView:didSelectRowAtIndexPath:
without segues nothing happens at all.

Make sure to connect the segue to the view controller itself and not the tableview row. Then in your didSelectRowAtIndexPath, you do a [self performSegueWithIdentifier#"mySegueID"];

Related

Navigation Bar subview tree might get corrupted issue

i am trying to send the view to next view but when i try to come back to the root page it crashes and say that Navigation Bar subview tree might get corrupted issue
- (IBAction)nxtBtn:(id)sender {
//here i am sending it to next view...
[self performSegueWithIdentifier:#"next" sender:(id)sender];
}
//function for segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//next is the name of the identifier
if ([segue.identifier isEqualToString:#"next"]) {
nextViewController *vc=(nextViewController *)segue.destinationViewController;
vc.str=sender;
}
}
we don't need any kind of identifier for simple use of segue i.e. navigating from one view to another without passing any data. just simple as that you have to connect the segue from one view to other and run the application. it will work properly.

prepareForSegue not being called from UITableView in a UIViewController

I have a UIViewController that contains a UITableView. The table view contains a custom UITableViewCell. The custom cell was built in interface builder and has a nib. In my main storyboard, I dragged a segue from the custom table view cell to the destination view controller. I set up the bare bones essentials in prepareForSegue, set a break point, but it never gets called.
I'm not that accustomed to using a UITableView in a view controller. I usually use a UITableViewController, but requirements dictate using the table view in a view controller. My initial assumptions is that most methods of doing things would be nearly identical, but I'm finding that not to be the case.
I tried setting the segue from the view controller itself and using didSelectRowAtIndexPath, and though it worked, the transition to the destination view controller was jerky.
Can anyone suggest what I might be missing in order to cause the prepareForSegue method to fire?
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
GaugeViewController *destination = [segue destinationViewController];
[destination setGaugeID:#"1"];
}
Thanks!
You need to refer to the identity of the segue in the Storyboard, something like this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
GaugeViewController *destination = segue.destinationViewController;
if([segue.identifier isEqualToString:#"yourSegue"]) {
NSLog(#"prepareForSegue called");
[destination setGaugeID:#"1"];
}else {
// do something else
}
}
Also don't forget to set the Identifier in the Storyboard.
Remember that push segues are used with Navigation Controllers and a modal segue can be dragged from view controller to view controller.

iOS - How to detect which button triggered a segue, and how to display its content based on the button

My problem is that I have a view with different buttons inside: all the buttons are connected to the same segue (this is for a particular reason, i know it would be easier to make different segues, but that's what i need right now).
How can I detect which button launched my new segue, and how can i change the data on the new segue bases on that decision? (for example, my new segue has in imageview, which should load a different image for every button)
in the method -prepareForSegue:sender:, in the sender parameter you has a reference to the control that launch the segue, for example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"yourIdentifier"]) {
UIButton *senderButton = (UIButton *)sender;
// do what ever you need with the button and segue
}
}

new view for menu for simple ios word game

I'm making a simple word game in Objective-C for iOS, and I started out by selecting "Single View Application", so I have one myProgramViewController.xib file, and one each of myProgramViewController.h and myProgramViewController.m. I just now realized that I would like to have a main menu type thing that loads first, and allows the user to select the length of the word, difficulty, stuff like that, and a "Go!" or "Start!" button. How can I add this menu view? I would prefer that the user could not go back to it (for now), so I'd rather not use the navigation bar.
Context in comments above.
When a segue happens, you can pass any data from one ViewController to another. What I would do in your case is set up with a storyboard, have the menu controller be the initial view controller, then have the game screen be a modal segue from that.
In the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender (on your MenuViewController) you can get segue.destinationViewController and set the data on it.
Example:
MenuViewController ---- playGameSegue ----> GameViewController
In MenuViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
GameViewController * destination = (GameViewController*) sender.destinationViewController;
destination.anyPropertyYou'veDefinedInGameViewController.h = DATA;
destination.otherProperty = DATA;
}
You can present the view modally. Say you have a view called MainMenu, which has a .xib,.h and .m file.
In your myProgramViewController.m file, you can call the code
MainMenu *mainMenu = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self presentModalViewController:mainMenu animated:YES];
Then in your MainMenu.m file, once the user has made their selections, call:
[self dismissModalViewControllerAnimated:YES];

custom UITableViewController cell segue not pushing

I have a custom UITableViewController showing a TableView with a list of locations, I created a segue in the storyboard (ios 5) and gave it an Identifier "SelectPlace", it's coming out of a cell in the first UITableViewController and is supposed to segue to the next UITableViewController showing a new tableview with a list of details of the location chosen.
Problem is the segue does not perform (next TableViewController is not pushed into screen, current one stays on) even though I double checked for the correct identifier and set everything in place.
I even see (breakpoints) the -prepareForSegue happening and completing successfully.
I also tried adding
[self performSegueWithIdentifier:#"SelectPlace" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
to the cell selection
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
but it did not help (and I don't think it's neccasary because the segue is drawn on the storyboard)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog([segue.identifier description]);
if ([segue.identifier isEqualToString:#"SelectPlace"])
{
NSArray* placePhotosArr = [FlickrFetcher photosInPlace:[self.topPlacesArray objectAtIndex:([self.tableView indexPathForCell:sender].row)] maxResults:50];
[segue.destinationViewController setPlacePhotosArray:placePhotosArr];
//[segue perform];
NSLog([placePhotosArr description]);
}
}
what's missing???
please help
I don't know if this will make a difference but I use this implementation:
[[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE"]
and is it a push or what type of transition are you using
My bad, the reason the segue was not pushing was because I forgot to 'embed' the tableviewcontroller in a navigation viewcontroller... duh