Sugan S
Sugan S

Reputation: 1778

unable to navigate to Destination View Controller in Storyboard in IOS

Hi I am using storyborad to create UI in IOS.eveything is fine but its not navigating to next view controller.I am using code as below

[self performSegueWithIdentifier:@"identifier" sender:self]; and 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if([segue.identifier isEqualToString:@"identifier"]){

      ViewController *destVC =(ViewController *) [segue destinationViewController];

   }

My Tableview delegates

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"InfoCell";


        HMSForumInfoCell *cell = (InfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"InfoCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            NSLog(@"Cell created");
        }


        NSDictionary *detailsDic = [_filteredListOfForums objectAtIndex:indexPath.row];


        [cell.headLinesLabel setText:[detailsDic objectForKey:kTopic]];

         // Adding underlined Colored text using NSMutableAttributedString

        NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:[detailsDic objectForKey:kCreatedby]];


        UIColor* textColor = [UIColor colorWithRed:255.0f/255.0f green:198.0f/255.0f blue:0.0f/255.0f alpha:1.0f];
        [commentString setAttributes:@{NSForegroundColorAttributeName:textColor,NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0,[commentString length])];

        [cell.nameButton setAttributedTitle:commentString forState:UIControlStateNormal];


   //     [cell.nameButton addTarget:self action:@selector(replyButtonAction:) forControlEvents:UIControlEventTouchUpInside];


        [cell.nameButton addTarget:self action:@selector(namebuttonPressed:) forControlEvents:UIControlEventTouchUpInside];


        [cell.replyButton addTarget:self action:@selector(replyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];



        return cell;
    }

    - (void)replyButtonPressed:(id)sender {


            [self performSegueWithIdentifier:@"id1" sender:self];

    }

    - (void)namebuttonPressed:(id)sender {


        [self performSegueWithIdentifier:@"id2" sender:self];


    }

Please correct me where am doing wrong. P.S: I have connectd View Controller properly with segueIdentifier in story board and changed class name of VC to my Class.

Upvotes: 0

Views: 505

Answers (2)

user6527451
user6527451

Reputation:

This code will be really useful to you to change the view controller using Storyboard ID.

For example - There were 2 view Controllers named FirstViewController and SecondViewController respectively. If you want to move from FirstViewController to SecondViewController there is a simple Code using Storyboard ID.

Step 1 :-

Enter the StoryBoard ID for both the ViewControllers

Step 2 :-

Write a code in FirstViewController -

let secondVC =  self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController

self.navigationController?.pushViewController(secondVC, animated: true)

Upvotes: 1

DerWOK
DerWOK

Reputation: 1061

Your code in performSegueWithIdentifier actually does nothing. So to show the destination scene you must wire it in Interface Builder like so:

  • Embed the first scene in a navigation controller (menu: Editor / Embedd / Navigation Controller)
  • Create the second scene
  • create a control on the first scene that triggers the second scene
  • Wire (Ctrl-Drag) the control from the first scene to the second scene
  • On "mouse button up" the pop up menu select the option "push" from the segue

Then it should look like this and should work:

enter image description here

Hope this helps.

Upvotes: 0

Related Questions