TableView data pass to other tableView AND navigation controller - ios

Firstly, I tried all segue codes but not true result...
(iOS 7) My storyboard starts with Tab Bar and has a Button to Model -> Table View with Navigation Controller. That TableView has JSON datas. If click a cell you pass to another tableViewController with push segue.
My push codes:
KatAltViewController * ilet = [[KatAltViewController alloc] init];
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
ilet.cid = currentKategoriler.cid;
[self.navigationController pushViewController:ilet animated:YES];
First tableView has not problem but if you click a cell to second table view, console gives that error:
2013-12-23 17:08:59.871 project02[3903:70b] nested push animation can result in corrupted navigation bar
2013-12-23 17:09:00.238 project02[3903:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
So, i click Back button in second tableview: screen is black!
2013-12-23 17:10:34.081 project02[3903:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'
how I fix that?

If you already have NavigationController in your storyboard and if you use this code
[self.navigationController pushViewController:ilet animated:YES];
you call 2 times to NavigationController.
So can you try this code part?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
passElement=[array1 objectAtIndex:indexPath.row];
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:#selector(passToOtherTableView) userInfo:nil repeats:NO];
}
-(void)passToOtherTableView{
[self performSegueWithIdentifier:#"passSegue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"passSegue"]){
SecondTableViewController *controller = (SecondTableViewController *)segue.destinationViewController;
controller.value = passElement;
}
}
I hope this can be help for you.

thanks for all answers.
Yes #TwentyThr23, i called two times NavigationController...
I deleted these codes, because I already push cells on storyboard;
KatAltViewController * ilet = [[KatAltViewController alloc] init];
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
ilet.cid = currentKategoriler.cid;
[self.navigationController pushViewController:ilet animated:YES];
and I added these lines;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"altKategoriS"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
KatAltViewController *destViewController = segue.destinationViewController;
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
destViewController.cid = currentKategoriler.cid;
}
}

Related

Application tried to push a nil view controller on target in didSelectRowAtIndexPath

We have two UIViewControllers
firstViewController
SecondViewController
.When we click on the UItableViewCell we want it to segue to the SecondViewController.
We tried like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard;
destinationController = [[UserDetails alloc] init];
destinationController = (UserDetails *)[storyboard instantiateViewControllerWithIdentifier:#"User"];
destinationController.FriendlyName.text=[usernameFriendlyName objectAtIndex:indexPath.row];
UIBarButtonItem * backButton =[[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:self action:nil];
destinationController.navigationItem.backBarButtonItem = backButton;
[self.navigationController pushViewController:destinationController animated:TRUE];
}
Please guide to us .What wrong in our code.
No need to do all this. Just connect the two viewControllers with the Push segue. Give some identifier to segue and simply write this line in didSelectRowAtIndexPath
[self performSegueWithIdentifier: #"Your segue identifier" sender: self];
To pass data from one view to other use PrepareForSegue method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"Your segue identifier"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
}

Failed to push to a View Controller in iOS

I'm a very beginner to iOS development. I made a navigation application in iOS to view some details in another view when table view cell tap. I did the following code,
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LawyerViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"LawyerViewController"];
NSLog(#"%#",[self.myObject objectAtIndex:indexPath.row]);
dvc.lawyer = [self.myObject objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dvc animated:YES];
}
This is going to the next view. But dvc.lawyer is not null here. It's null on Next View page.
Reading the Value in Next page
NSLog(#"%#",self.lawyer.firstName);
How can I fix this.
Thanks in Advance!
You are supposed to instantiate ViewControllers in another way, if you use storyboard segues. You need to implement prepareForSegue where you can Access the segues destinationViewController like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE"])
{
// reference to the destination view controller
LawyerViewController *vc = [segue destinationViewController];
// Pass any data
vc.lawyer = self.myObject[[self.tableView indexPathForSelectedRow].row]; // Not tested
}
}

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.

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