Navigating pages in different tableview - ios

I have created a screen containing two table views where i have successfully called the method cellForRowAtIndexPath but now am facing trouble in navigating to the other page from tableview option by using didSelectRowAtIndexPath.I think am doing some mistake and i have clearly no idea what is the next step.Can anyone guide how should i do it?? I have used this code-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:leftTableView]) {
TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooSinglesScreen"];
EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:#"EyecatcherScreen"];
TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooToplist"];
int i=indexPath.row;
if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}
}
else {
TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooSinglesScreen"];
EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:#"EyecatcherScreen"];
TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooToplist"];
int i=indexPath.row;
if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}
}
}

If you want to navigate from table view to another view controller don't set animated:NO.set animated:YES for navigating.But if you set animated:NO,definitely it does not navigate.So you have to do following things for navigating.
YourViewController *yourVC = (YourViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"StoryBordIdentifier"];
[self.navigationController pushViewController:yourVC animated:YES];
Also You can use in this didSelectRowAtIndexPath
[self performSegueWithIdentifier:#"segueID" sender:self];
with
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
YourViewController *vc = segue.destinationViewController;
}
Click Table Row and Go another Page
Segue or didSelectRowAtIndexPath
Making Push Segue when table row is selected

I see user3182143's answer helped, but for what it's worth I've set up a tiny demo project (now updated with two tables) to show anybody interested how it's done.
It also illustrates (as the name implies), that you can, indeed, push manually and set the animation parameter to NO, just run it in the simulator.
I can't tell why that didn't work in your original approach, pri, but my guess is that you set up your navigation view controller wrongly somehow.
For code & storyboard readability I'd recommend using segues anyways.

Related

Push a view when click the tableviewcell

I want to push a view when I click the cell of my tableview.The code is as followed:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == todoTableViewTag) {
NSLog(#"aa");
ViewControlleraaa* testvc = [[ViewControlleraaa alloc] initWithNibName:#"ViewControlleraaa" bundle:nil];
[self.navigationController pushViewController:testvc animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
but it does not work at all.
I have
ViewControlleraaa.h ViewControlleraaa.m and ViewControlleraaa.xib
but I did nothing except creating them.
So where is the problem?
Create a 'generic' segue from your table view controller to ViewControlleraaa and use 'performSegueWithIdentifier'. If that approach is not possible to execute then you may want to try 'presentViewController' instead.
Try creating a manual segue from your table view controller to ViewControlleraaa. Then, as the answerer above me said, you can use performSegueWithIdentifier to call the segue. If you should ever need the table view controller to push any data to the ViewControlleraaa, you can do so using the "prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender" method. The destinationViewController property of "segue" is ViewControlleraaa.
Here's a link to a YouTube video, in case you need any additional help: https://www.youtube.com/watch?v=XApYtAlRDVE
Check self.navigationController is not nil then surly it will work fine.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}

How can i add 2 segue on 1 action?

I have a tableview which is showing my array items. . I connected push style segue to detailviewcontroller screen with my storyboard but i dont want to all items go detailviewcontroller so i made a controller like that ;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if (sender == self.btnEkle) return;
if (sender == self.btnKrediKartlarim) return;
NSString *bankaAdi = [[mainList objectAtIndex:indexPath.row] objectForKey:#"BankaAdi"];
if (bankaAdi.length > 1) {
KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"KartDetay"];
[self presentViewController:vc animated:YES completion:nil];
}
If bankaAdi.length > 1 my app should go to the KartDetay
if its not i mean else my app should go to the detailviewcontroller
these codes are working but there is an error in my compiler.
Unbalanced calls to begin/end appearance transitions for .
Sorry for my English i know i didn't describe myself clearly but please try to help me.
Thanks !
---UPDATED AREA----
First of all Thank you for answer.But it doesnt work or i couldnt do that.
1- I created 2 manuel different segues to my KartDetay("taksit" segue name) and my DetayEkran("detay" segue name)..
2-I used with these codes..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *indexPath2 = [self.tableView indexPathForSelectedRow];
bankaAdi = [[mainList objectAtIndex:indexPath2.row] objectForKey:#"BankaAdi"];
if (bankaAdi.length > 1)
{
[self performSegueWithIdentifier:#"taksit" sender:nil];
}
else
{
[self performSegueWithIdentifier:#"detay" sender:nil];
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"taksit"])
{
//if (sender == self.btnEkle) return;
//if (sender == self.btnKrediKartlarim) return;
KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"KartDetay"];
[self presentViewController:vc animated:YES completion:nil];
}
else
{
DetayEkran *detayEkran = [self.storyboard instantiateViewControllerWithIdentifier:#"DetayEkran"];
[self presentViewController:detayEkran animated:YES completion:nil];
}
When I run my app and tap my first cell which is bankaAdi>1.
App can go to KartDetay screen but my compiler says :
Unbalanced calls to begin/end appearance transitions for .
Thank you for answer again.
----ReUpdated Area --- problem is solved by Greg... Thank you for that Greg...
I made a huge mistake with these codes coz i call another DetayEkran *detayEkran = [self.storyboard instantiateViewControllerWithIdentifier:#"DetayEkran"];
[self presentViewController:detayEkran animated:YES completion:nil];
in my prepareforsegue method. When i delete all instantiate codes in my prepareforsegue methods my app working fine...
So
Greg codes are working like a charm.. Thank you Greg !
When the segue is called the prepareForSegue:segue method is called and it handles the transition, you shouldn't call presentViewController or push view controller manually.
The best way to do that is create two segue for KartDetay and detailviewcontroller with two different identifiers in storyboard.
And override didSelectRowAtIndexPath method, where you check your condition and run appropriate segue:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *bankaAdi = [[mainList objectAtIndex:indexPath.row] objectForKey:#"BankaAdi"];
if (bankaAdi.length > 1) {
[self performSegueWithIdentifier:#"YOUR1IDENTIFIER" sender:nil]
}
else
[self performSegueWithIdentifier:#"YOUR2IDENTIFIER" sender:nil]
}
If you need to pass any parameters use prepareForSegue method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"YOUR1IDENTIFIER"]) {
KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"KartDetay"];
[self presentViewController:vc animated:YES completion:nil];
}
else {
//handle other view controller
}
}
Just remember to replace segue identifiers with your one.
The prepareForSegue:sender: method is invoked before opening the detail view controller. It is the place to prepare for the transition, not to present/push view controllers. The actual transition is done after the method has been invoked. Whether push or present is used, depends on the segue type in the storyboard.
Try using the tableView:didSelectRowAtIndexPath: method instead of the prepareForSegue:sender: method. This should solve your problem.

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.

Table View View Controller Show Next View

Im working with table view controllers within story board.
I currently have one tableview controller embedded in navigation controller in my storyboard. This table view controller is linked to an ObjectiveC file.
Through code i can display another table view controller with the correct data using the tableView didSelectRowAtIndexPath method.
code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
[self.navigationController pushViewController:detailViewController animated:YES];
}
But if i try to add another table view controller in storyboard, associate it with an objectiveC view controller file and connect the first TVC to it, That table view controller is not shown upon running the code.
I need to customise the second table view visually and have tried to use a segue push...as follows:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"show"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
//WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
WorkoutSetViewController *destViewController = segue.destinationViewController;
destViewController.workoutType = workoutType;
//[self.navigationController pushViewController:detailViewController animated:YES];
}
}
But when i run this code, the second table view controller doesn't even load although the application doesn't crash.
Whatever I am doing wrong must be simple, any help would be appreciated.
Thank You
Simple You have to navigate through below code. (No need to set storyboard when you working in same storyboard ViewController)
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexpath.row==0)//for first row click
{
WorkoutSetViewController *objWorkoutSetVC=[[WorkoutSetViewController alloc] i nitWithNibName:#"WorkoutSetViewController" bundle:nil];
[self.navigationController pushViewController:objWorkoutSetVC animated:YES];
}
else if(indexpath.row==1)//for second row click
{
//Put code in which screen you have to navigate
}
}
Do NOT Alloc init your new view controller. Use this code instead:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
WorkoutSetViewController *detailViewController = (WorkoutSetViewController *)[storyboard instantiateViewControllerWithIdentifier:#"coolID"];
[self.navigationController pushViewController:detailViewController animated:YES];
For MainStoryboard write your storyboard name and for coolID write your view controller id name which you set in your storyboard.

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