I am trying to create push segue from view. Maybe image would be best for describing:
I started from sample ECSlidingViewController project (BasicMenu) and I am trying to expand first ViewController (Home) to another ViewController. I get it and I can go from selected row in tableView to the controller. But when I am in controller and I tap on Back I am at different screen from first one (it's blank screen with button at upper left). I guess I must set something more to get this working but I don't know what. Thanks
Updated:
Code from first view controller to go to next view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Find the selected cell in the usual way
UITableViewCell *cell = [self.searchResultsTableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:#"selectedSegue" sender:cell];
}
I found that the problem is with code in method didSelectRowAtIndexPath. When I removed it. The segue is performed well and I go to other view controller and when I tap on top left button I get back where I was. It's okay.
So I guess the real problem was with sender in performSegueWithIdentifier.
But I need send to new controller some information about selected row. So I used this answer.
Related
I have a ViewController, for example startingScreenViewController. I have a push segue from an item on this view to another view (someViewController) which is a ViewController that has a TableView (not TableViewController of course) in it. Now, without having a back button I want to go back to the first view by tapping on a cell in table view. I have written my cell delegate:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
I tried using
[self.navigationController popViewControllerAnimated:YES];
and obviously it didn't work, since I don't have a navigationController. I even tried to segue back to the startingScreenViewController which was a stupid thing to do and also didn't work.
I'm in need of some help, and suggestions would be much appreciated.
I don't know how you manage to open someViewController with push segue without UINavigationController, but if it works, try to use this code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self dismissViewControllerAnimated:YES completion:nil];
}
And, of course, check, is your view controller delegate of table view.
The short answer is to not use a push segue when you don't have a navigation controller. That should not work at all, and the fact that it does work is an accident. There is no guarantee that it will continue to work in the future.
Use a modal presentViewController:animated:completion call, the dismiss it using the corresponding call.
I'm brand new when it comes to app development so this might be a stupid question.
So i have made a UI table. It is customizable, as in users can insert or delete rows. I want to allow users to click on a table cell and it'll direct them to another view controller. All the view controllers will look the same for each cell (sorta like a template). Any idea how to implement this using storyboard?
Appreciate it!
You do not need an array of view controllers. All you need is one view controller, which gets instantiated when the user clicks the cell to navigate to it, and gets deallocated as soon as the user closes the screen to go back to your main view controller.
All you need to implement this in your storyboard is adding a push segue from a cell or a button in your main view controller to your "detail" view controller. When the segue gets triggerred, your code gets a chance to configure the newly created "detail" view controller in the prepareForSegue:sender: method, before the controller's view appears on the screen. This is the place where you customize the data that shows up in the detail view (presumably, depending on the particular row in the table that has triggered the segue).
Here is a link to a good tutorial explaining how to build a master-detail application with Xcode and storyboards.
In storyboard you create a viewcontroller that will display the data after a cell has been selected, you will only need one and not an array. Link it from the tableviewcontroller to the new viewcontroller. Click the segue in Xcode and in the inspector give it a unique identifier.
tableView:didSelectRowAtIndexPath: will get called when you select a cell, here you can perform the segue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedObject = ... // store the object that was selected
[self performSegueWithIdentifier:#"mySegue" sender:self];
}
In your tableviewcontroller you make sure you implement prepareForSegue:sender:. Here you can hand over the correct model object to populate your destination viewcontroller with data.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"mySegue"])
{
MyDetailViewCotroller *controller = [segue destinationViewController];
controller.dataObject = self.selectedObject;
}
}
Check out this example code from Apple (does not used Storyboard though): http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416
I have a UITableView in which I want to let user to click on the cell and use a sub view to display the detail information. I have tried this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubMainViewController __autoreleasing *mSubView = [self.storyboard instantiateViewControllerWithIdentifier:#"mainSubView"];
[self presentViewController:mSubView animated:YES completion:nil];
}
This seems to be working, however, I couldn't get back to my table view, could anyone help me out?
Well it seems you want to load a detailview when user selects a cell and you want the user to be able go back to the previously view when back or some button like that is pressed. You need to use navigation controller for that. Here is the link to apple's doc http://developer.apple.com/library/ios/ipad/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
And here is a sample tutorial to get you started
http://razell.hubpages.com/hub/IPhone-Guide-Loading-a-detail-view
Hope this helps, let me know if you need any more help.
EDIT:
So according to your comment you are looking for a modal view to pop up over the view. Well here is a link to whole a lot of different ways to achieve that, and they all have example projects too so you can actually see how the trick is executed.
http://samwize.com/2012/12/06/7-ios-custom-popup-views/
In your SubMainViewController you need to dismiss the your current viewcontroller using
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
I'm little lost here. I have a basic master-detail aplication, and I want to change the detail view according to the selected row in MasterViewController, but the views have different content, one has an image gallery, and the other one will load a video on full screen. It's not just refresh the detail view, have to load another view. How is the better(fast) way to do that?
I'll suggest you to use a replace segue.
Just create a segue to the desired view initiated by your row with a Style: Replace, and Destination: Detail Split.
Segues were introduced in the iOS 5 SDK
EDIT:
These are step-by-step instructions to accomplish what you need.
From now on:
the item that should be pressed for the action to take place (a button or row in master view) = *Button;
the view you want to be placed in the iPad's detail view = *Detail.
just a bit for naming for ease of explanation
Hold ctrl click on *Button then hold and drag to *Detail and release to create your segue.
In the popup pick Replace
Select your segue, open Attributes inspector and set Destination to Detail Split
That's all.
More on segues: http://www.scott-sherwood.com/?p=219
Specifically, in CS193P, check out the latest version, and look at lecture #7. Paul doesnt finish the part with the replace Segue, but he DOES provide an example with very good reusable code (Psychologist with Dr Pill)
If you are using a dynamic tableview in your MasterViewController, implement numberOfRowsInSection:(NSInteger)section Method with:
return [_youDataArrayNameHere count];
then on cellForRowAtIndexPath configure the cell:
cell.textLabel.text = [_youDataArrayNameHere objectAtIndex:indexPath.row];
and in didSelectRowAtIndexPath, call any other view based on the selected row:
//
if (indexPath.row == 0) {
[_detailViewController.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"anotherVC01Here"] animated:YES];
}
I don't seem to get this SIGABRT I keep getting. I have this storyboard iOS application, and in the storyboard I have a UITableViewController. Now, I can take a cell of the TVC and make it push the "segue" view controller, but what if I needed to stop the "segue" action on certain conditions? Apparently you can't, since the prepareForSegue:sender: method doesn't allow for it, and it seems to be the only callback that gets called when a transition is about to get performed.
So I guessed I could go into the tableView:didSelectRowAtIndexPath: and perform the segue programmatically. Suboptimal, but still…
Well, it turns out I guessed wrong. Or at least, I'm doing something wrong. The most obvious way to do it would be
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"TheOtherIdentifier" sender:self];
}
but the whole app crashes with a SIGABRT, which does not give any useful information (and yes, I'm sure it's that line that makes the app crash, I checked with the debugger :) Moreover, the VC I'm trying to load has the identifier correctly set, because the following code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"TheOtherIdentifier"];
[self.navigationController pushViewController:vc animated:YES];
}
"works". Quotation marks indicate that this is clearly not the way such a transition should be performed.
Now: ideas?
Try this:
Use the first code block and not the second.
In storyboard control drag from the cell to the other view controller. Note that a segue is created.
Click on the segue. Use the attributes inspector to give the segue and identifier "theOtherIdentifier" (lower case "t" recommended). Also select a segue style of "push" assuming you are using a navigation controller.
Storyboard will instantiate the other view controller. Be sure you are not doing this in your code.