ipad vs iphone differences in storyboard and segues - ipad

This is my first iPad/Storyboard/SplitViewController and it has a table as the master and each row is a separate document for the detail view. I am starting from the Xcode 4.2 template.
I have gotten the iPhone half to work. I hooked up a segue from the tableviewcell and get the call:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
And with that I can bring up the detail view correctly.
On the iPad storyboard, I don't get the prepareforsegue call. I have tried creating a segue between the masterviewcontroller and then tried the tableviewcell controls but can't get it to call my prepareforsegue.
I also tried:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"segueDetailIpad" sender:nil];
}
That will call my Segue, but the tableview doesn't have an indexPath set. (It is set on the iPhone though).
Also, when I switchback to the iPhone version, it wants to call the same performseguewithidentifier (as above), but then I have to switch between different #"segueDetailIpad" parameters.
It seems to me I am mixing "old" and "new" models and need to find some way to
get the iPad to use the segue and not rely on the didSelectRowAtIndexPath.
Hope this is enough for some suggestions ;-)
thx!

Just as user589310 said I was able to solve my similar problem by embedding the [segue destinationViewController] in a UINavigationController.
For example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue destinationViewController] class] == [UINavigationController class])
{
[[[[segue destinationViewController] viewControllers] objectAtIndex:0] setDelegate:self];
}
else
[[segue destinationViewController] setDelegate:self];
}

Related

Segue to same view Controller loads before prepareforsegue is called

Hi guys i am a beginner on Obj c Programming, I have created a "self segue"(segue to same view controller) from a tableviewcell. Now my problem is, i am setting few parameters in the prepareForSegue method, but somehow the segue already happens before this method is called(i am not even calling "performSeguewithIdentifier"). I understand that this might be because the segue is associated with the cell. But i found no other way to create a "self-segue"
please help.Btw i am using xcode6..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selctdObj = [avObjArray objectAtIndex:indexPath.row];
if([_selctdObj isContainer])
{
[self performSegueWithIdentifier:#"isContainerSegue" sender:self];
}
else
{
[self performSegueWithIdentifier:#"isItemSegue" sender:self];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"isContainerSegue"]) {
// Get destination view
serverBrowseVC *sbvc = [segue destinationViewController];
[sbvc setServerSelected:_serverSelected];
[sbvc setBrowseObjID:_selctdObj];
}
}
Now invariably "isContainerSegue" gets executed ,even is the object is not a container. i also tried commenting the
//[self performSegueWithIdentifier:#"isContainerSegue" sender:self];
But every time "isContainerSegue" gets executed..
You said you weren't calling performSegueWithIdentifier, but you are. You shouldn't be if you've connected the segue from the cell. You also shouldn't implement didSelectRowAtIndexPath at all, just prepareForSegue. You can get the indexPath from the sender argument (the sender will be the cell) of prepareForSegue:sender:. If you're having a problem with the "if [_selctdObj isContainer]" clause, you need to post what isContainer does.

UITextLabel only updates on second selection of cell in Navigation Controller

I have a project with a TabBar Controller with a Navigation Controller and other View Controllers on it.
In my Navigation controller i have a sequence of 3 view controller and the last of them, DetailViewController, is being presented using a modal transition. I'm parsing strings between my 2nd and 3rd view controllers, but my labels displaying the information on the 3rd one only display after selecting a cell twice, and the information that shows is the one corresponding to the first selection of the cell.
Heres my 2nd view controller (ViewController) method prepareForSegue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
titulo=[nomeEvent objectAtIndex:indexPath.row];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"nextView"]) {
DetailEventViewController *myVC = [segue destinationViewController];
myVC.tituloEvento = titulo;
}
}
The property tituloEvento is declared in the second view controller's .h and in viewwillappear I set my labels text.
This might be happening because prepareForSegue is getting called before didSelectRowAtIndexPath:. Here is what I would do:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"nextView"]) {
DetailEventViewController *myVC = [segue destinationViewController];
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
myVC.tituloEvento = [nomeEvent objectAtIndex:selectedIndexPath.row];
}
}

prepareForSegue not sending parameters when called, resulting in a crash

I have two segues going out of my initial view controller. The push segue is connected to the cell and the modal is connected to the + UIBarButtonItem.
When this is what my prepareForSegue code looks like, everything is fine and filePath is sent through the push segue, but the filePath isn't passed through the modal segue.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showTimes"]) {
[[segue destinationViewController] setFilePath:filePath];
}
// if ([[segue identifier] isEqualToString:#"addEvent"]) {
// [[segue destinationViewController] setFilePath:filePath];
// }
}
If I uncomment the second if statement and segue identifier, the app crashes. filePath is sent nowhere. I've tried moving [[segue destinationViewController] setFilePath:filePath]; out of both if statements in an attempt to ensure that that line was executed, but that also crashes my app.
Both segues have the correct identifiers set up in the Attributes. However, I'm not sure that Xcode is actually realizing that the correct identifiers are set up because when I change the segue types, those changes aren't reflected the next time I run the app.
I'm a loss for what to do. I'm relatively new to Objective-C.
The addEvent segue points to a navigation controller, not your view controller. Instead, get your view controller and set the file path on that:
[[[segue destinationViewController] topViewController] setFilePath:filePath];

storyboard push segue isn't properly animated

I'm new to iOS development and don't get on well with storyboard.
screenshot of storyboard: http://i.stack.imgur.com/s9VTB.png
I have got the push segue working now. But only pushing from the first tableViewController to the second one is animated and pushing back isn't animated.
In the first tableViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"xxx" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"xxx"]) {
// set some properties of segue.destinationViewController
}
}
the second one is not modified.
Update:
I deleted the storyboard, did all of them programmatically and now everything works well.
Sometimes storyboard is just so confusing...
Whether the segue is animated will depend on how you do it. Try:
[self.navigationController popViewControllerAnimated:YES];

Custom segue in storyboard

I have a Master-Detail application.When the user selects a row in the MasterTable, I want to open another Table (not the DetailViewController). It should paper besides the MasterViewController, similar to the Facebook app on iPad.
I have a Custom segue from the MasterViewController to this table (DocumentViewController of type UITableViewController). This DocumentViewController is 'Embedded' in a navigation controller.
In short, the items on my storyboard look like this:
navigationController->MasterViewController->navigationController->DocumentViewController.
The segue is from MasterViewController to navigationController.
Do I have to perform the segue in "didSelectRowAtIndexPath"? Or do I have to use "performSegueWithIdentifier" in didSelectRowAtIndexPath?
If I understand your question correctly, the segue should be from MasterViewController to DocumentViewController. Make sure to give it a unique identifier, and then reference what you want to do in the prepareForSegue in your MasterViewController.
Example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showList"]) {
// gets indexPath for the currently selected row in my UITableView
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// pull back some useful data from Core Data according to what was selected in my UITableView.
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// listDataItem is a property of the controller (in this case a UITableViewController)
[[segue destinationViewController] setListDataItem:object];
}
}

Resources