iOS Perform segue after dismissing view controller - iphone

My app stores user configurations with two different view controllers. The first is only presented when the create a new configuration, which is the name of the configuration. The second is the configuration itself which is normally brought up by accessoryButtonTappedForRowWithIndexPath
Is it possible that when they dismiss the first view controller where they set the name:
[self.delegate addViewerViewController:self didFinishAddingItem:viewer];
That it presents the configuration view controller straight away without having to tap? Normally this is called by
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
nameAtAccessoryIndex = [viewerKeys objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"EditSettings" sender:indexPath];
}

It looks like you're using performSegueWithIdentifier: improperly. Your sender should be self.
Add prepareForSegue: to your view controller, and set viewer on segue.destinationViewController inside it.

Related

Developing a simple Course Management System for iPhone using Xcode using Table Views only

I have to build a Course management app. I am using table views only for this app. Using the table view controllers.
The first view contains the semesters - 1,2,3,4....12.
The second view contains details that are respective to the previous table view controller.
The details in the second table view controller are: Lectures, Papers, To-do list, Record lecture.
Depending on the user's selection, he can access Lectures, Papers, List, Record Lecture for that particular semester.
I am not able to figure out how to pass data from the third view to the fourth and subsequent views. For eg. Lecture->Lecture 1: Introduction->Download PDF.
How do I assign a specific table view controller when the user taps a particular cell? using seques or cellForRowAtIndexPath method?
I am confused.
Kindly help me in this regard. Your help will be highly appreciated.
You will do that in the didSelectRowAtIndexPath. Here you prepare the view you want to present and push it into the your navigationController. For instance:
// On user tap, present the details you want.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithDictionary:dict];
[self.navigationController pushViewController:detail animated:YES];
}
Additionally, these are some relevant links for what you are trying accomplish:
-Navigation Controllers
-Table Views
Do the selection part in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

iPhone: TableViewController nibName error with "initWithNibName:bundle:"

I have a dynamic cell UITableViewController and I want to push a specific View Controller when someone taps a cell. So I'm trying to use the pre-made method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
But when I go into the simulator and tap a cell, this is what I get:
"NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle [...] with name 'AffichageVotesQuestionDuMomentViewController'.
Within the method, I have this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
AffichageVotesQuestionDuMomentViewController *detailViewController = [[AffichageVotesQuestionDuMomentViewController alloc] initWithNibName:#"AffichageVotesQuestionDuMomentViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
AffichageVotesQuestionDuMomentViewController is a custom view controller I created myself. I also tried creating another random one and I get the same type of error. If I set the initWithNibName: to nil, it segues to a view controller that has the navigation bar on top, but that's completely black.
Now, I'm a beginning iPhone programmer and have a very poor understanding of nibs, nib names and such. Any help is appreciated. Also, I didn't do any segue in the storyboard or anything, since it seems I'm programmatically creating the view controller and pushing that way. If there's a good way to do it with segue though, I'm okay with that too (but I need to know the row of the tapped cell).
Thank you!
Because you're using IB storyboards you should do something lik this i think:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"mystoryboard" bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"AffichageVotesQuestionDuMomentViewController"];
... instead of using the "initWithNibName"-initializer which is used for the classical xib-based approach.

Change views via code using xcode 4.2 and storyboard?

How would I go about changing views via code using xcode 4.2 and storyboard?
I'm trying to change views once a dynamic table view cell is clicked.
Since its dynamic I can't just link it with a segue...
I've tried changing using this code as suggested by another article on Stack Overflow but it doesn't work:
UIViewController *alertView = [self.storyboard instantiateViewControllerWithIdentifier:#"alertView"];
[self.navigationController pushViewController:alertView animated:YES];
Here's a snippet of my code, hope it helps!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==0){
UIViewController *alertView = [self.storyboard instantiateViewControllerWithIdentifier:#"alertView"];
[self.navigationController pushViewController:alertView animated:YES];
NSLog(#"This code is being called...");
}
In your storyboard create a segue from your UITableViewController to your alertView. Make sure you do it by control dragging from the Controller (next to the First Responder icon) to your alertView rather than dragging from your table cell or something like that. Choose a segue type of 'Push'. Click on the segue's properties and make sure to give it an identifier like AlertViewSegue
Now you can programmatically invoke your segue with code like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==0){
[self performSegueWithIdentifier:#"AlertViewSegue" sender:self];
}
}
this is one of the better storyboard tutorials and it happens to use tableviews.
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

How to call a detail view from a table view within a Storyboard

I have following problem.
I have created a tab based Application with three Views and Viewcontroller.
FirstView(Start screen stuff), SecondView (Detailpage), ThirdView (Table for listing items).
(Connections from storyboard were set automatically).
In the third view a table is integrated and the content is displayed fine.
Now I would like to call the SecondView , when a row in the table is selected.
I also tried to add a forth View , outside the tabBar Controller, to get the Detailview, but this also did not help.
I have tried several tutorials and forum tips, but cannot get it working.
The class is set to the right ViewController, the identifier is set to detail.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
detail.label1.text = #"It is working";
}
When clicking on the row, it becomes blue, but nothing happens. No error Message , nothing.
Hope that you can help :-)
OK, I have tried to "optimize" my design.
Still have the tab based Views, but when clicking on a row in the table, a new (not linked in Storyboard) view should appear to display the details of the selected quote.
I have created a view in the storyboard and called it "detailzitat"
I have created a DetailViewController.h/m as UIViewcontroller class
I have set the custom class to DetailViewController
I import the DetailViewController.h in the ThirdViewController.h
I have modified the didSelectRowAtIndexPath method in ThirdViewController.h accordingly.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"detailzitat"];
[self.navigationController pushViewController:detailVC animated:YES];
}
and my DetailViewController.m looks like
#import "DetailViewController.h"
#implementation DetailViewController
#synthesize label1, labeltext;
- (void)viewDidLoad
{
[super viewDidLoad];
labeltext=#"JUHU";
label1.text=labeltext;
}
But again, nothing happens, besides the row gets blue.
I do not understand. If I am using this code in a Non-Storyboard project, it is working.
What am I doing wrong ? Is there any tutorial for this combination within Storyboards ? Have not found one for this approach yet.
Try to learn from the different tutorials on the web, but the biggest problem is, most ones are not for iOS5 and I am not so good to transfer then.
Hope to get some hints :-)
You might want to think about your design. If I am understanding your description correctly, the user will be on the third tab, tap on a row in a table, and then you will be switching them back to the second tab. A navigation controller might be a more natural, less confusing, choice there.
But in any case, something like this will work sometimes:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.tabBarController.viewControllers objectAtIndex:1];
detailVC.label1.text = #"It is working"; // <- this will not work consistently!
self.tabBarController.selectedViewController = detailVC;
}
The problem with this is that while the user is on that third tab, it's possible that the second tab view controller's view is unloaded (due to memory pressure for example).
It's also possible the user went from tab 1 to tab 3 immediately and therefore the 2nd tab's view isn't even loaded yet at all. (To even test the above code you would have to select tab 2 and then tab 3.)
If the second tab's view hierarchy is not loaded, the label1 property will be nil, and so this will not work. A better strategy would be to create a new #property of type NSString* on the DetailViewController. And set that property instead of trying to set the label1 directly.
Then in your viewWillAppear: for the DetailViewController you can update your labels as needed. At that point of course you can be sure that label1 is loaded and connected to the correct UILabel.
I hope that helps.
I think problem is at self.navigationController. If your view is not inside the navigation controller this will not work. So what you do is create a new navigation controller object there and then use it to show your detail view.

iPhone SDK: Pushed view controller does not appear

I want to add a detail view for one of the cells in my UITableView. I've created a new view controller SyncDetailViewController) and a NIB for the detail view. Didn't make many changes in the new class. Just added a label and outlet for it and connected nib with view controller.
Now I've added this code to my view controller (the one with UITableView, not the new one)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
SyncDetailViewController *dvController = [[SyncDetailViewController alloc]
initWithNibName:#"SyncDetailViewController" bundle:nil];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
The problem is that even if I select any row in the UITableView nothing happens. It doesn't produce any errors or warnings. I've added a breakpoint inside this method and it is reached so this code is executed.
Any ideas are much apprieciated.
"Nothing happens" sound so much like "sending a message to nil". Have you, by chance, checked that self.navigationController is not nil? Or that dvController is well initialized?