4

Changing views via code using xcode 4.2 and storyboard?

 2 years ago
source link: https://www.codesd.com/item/changing-views-via-code-using-xcode-4-2-and-storyboard.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Changing views via code using xcode 4.2 and storyboard?

advertisements

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];
    }
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK