Can I make a link to a button for an arbitrary controller in xCode?

I am completely new at this ..... sorry in advance. I created an application in xCode that contains 10 View controllers. Each view controller has an image view and a round rectangular button.

I would like to configure it so that clicking the button on the view moves to one of the other 9 views, but the view that loads should be random.

What i have done so far:

- I placed 10 relational controllers on the storyboard and set each class for the scene

-I created 10 Objective-C class-ViewControllers (.h and .m files) named scene1-10

- I created segues between them in this mod scene1 โ†’ scene2 โ†’ scene3 โ†’ scene4 โ†’ scene5 โ†’ scene6 โ†’ 7scene โ†’ scene8 โ†’ Scene9 โ†’ scene10 โ†’ SCENE1

-I set the class of each segue for segue1-10, naming them after the scene in which they go ((the segue between scene1 and scene 2 will be segue2)

-I made all .h files look like this (changing scene # depending on the file):

#import <UIKit/UIKit.h>

@interface scene1 : UIViewController

- (IBAction) randomButton;

@end

-I made all .m files look like this (scene change # depending on the view

#import "scene1.h"

@interface scene1 ()

@end

@implementation scene1

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction) randomButton : (id) sender
{
    int i = arc4random() % 10;
    if(i == 1)
    {
        [self performSegueWithIdentifier: @"segue1" 
                                  sender: self];
    }
    else if(i == 2)
    {
        [self performSegueWithIdentifier: @"segue2" 
                              sender: self];
    }
    else if(i == 3)
    {
        [self performSegueWithIdentifier: @"segue3" 
                                  sender: self];
    }
    else if(i == 4)
    {
        [self performSegueWithIdentifier: @"segue4" 
                                  sender: self];
    }
    else if(i == 5)
    {
        [self performSegueWithIdentifier: @"segue5" 
                                  sender: self];
    }
    else if(i == 6)
    {
        [self performSegueWithIdentifier: @"segue6" 
                                  sender: self];
    }
    else if(i == 7)
    {
        [self performSegueWithIdentifier: @"segue7" 
                                  sender: self];
    }
    else if(i == 8)
    {
        [self performSegueWithIdentifier: @"segue8" 
                                  sender: self];
    }
    else if(i == 9)
    {
        [self performSegueWithIdentifier: @"segue9" 
                                  sender: self];
    }
    else
    {
        [self performSegueWithIdentifier: @"segue10" 
                                  sender: self];
    }
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end

-I linked the received action "randomButton", specified for each view controller, to a button on the view controller

What's happening:

I get the โ€œIncomplete implementationโ€ warning in the โ€œ@implementation scene1โ€ line of each .m file, but the application creates and loads.

After loading, if I click the button, the application freezes and the xCode debug window appears with the following:

2012-05-05 07:11:11.789 randomTester[2448:f803] -[scene1 randomButton]: unrecognized                     selector sent to instance 0x686d370
2012-05-05 07:11:11.792 randomTester[2448:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[scene1 randomButton]: unrecognized selector sent to instance 0x686d370'
*** First throw call stack:
(0x13cc022 0x155dcd6 0x13cdcbd 0x1332ed0 0x1332cb2 0x13cde99 0x1914e 0x190e6 0xbfade 0xbffa7 0xbed8a 0x3e2cf 0x3e5e6 0x24dc4 0x18634 0x12b6ef5 0x13a0195 0x1304ff2 0x13038da 0x1302d84 0x1302c9b 0x12b57d8 0x12b588a 0x16626 0x1f5d 0x1ec5)
terminate called throwing an exception(lldb)

, . , , , .

!



UPDATE

, :

, , , , IBAction. . , , .

.ht :

#import <UIKit/UIKit.h>

@interface scene1 : UIViewController

- (IBAction) randomButton;

@end

.m :

#import "scene1.h"

@interface scene1 ()

@end

@implementation scene1

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)randomButton
{
    int i = arc4random() % 10 + 1;
    NSString *segueIdentifier = [NSString stringWithFormat:@"segue%d", i];
    [self performSegueWithIdentifier:segueIdentifier sender:self];

}- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end

, , , , , xCode :

2012-05-05 13:00:09.236 randomTester[2699:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:     'Receiver (<scene1: 0x6868f90>) has no segue with identifier 'segue5''
*** First throw call stack:
(0x13cb022 0x155ccd6 0xdd61b 0x2592 0x13cce99 0x1814e 0x180e6 0xbeade 0xbefa7 0xbdd8a 0x3d2cf 0x3d5e6 0x23dc4 0x17634 0x12b5ef5     0x139f195 0x1303ff2 0x13028da 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x224d 0x21b5)
terminate called throwing an exception(lldb) 

, view1 "segue5" ( , IBAction). , segue5 view1 , 2, .

, 10 segues 1 segue1-10. segues 2-10 2-10 . , segue1 , , . segue, scene1 scene1, segue scene2 segue1.

, App :

2012-05-05 13:45:04.467 randomTester[2803:f803] -[scene1 randomButton:]: unrecognized selector sent to instance 0x68b3760
2012-05-05 13:45:04.479 randomTester[2803:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:     '-[scene1 randomButton:]: unrecognized selector sent to instance 0x68b3760'
*** First throw call stack:
(0x13cb022 0x155ccd6 0x13cccbd 0x1331ed0 0x1331cb2 0x13cce99 0x1814e 0x180e6 0xbeade 0xbefa7 0xbdd8a 0x3d2cf 0x3d5e6 0x23dc4     0x17634 0x12b5ef5 0x139f195 0x1303ff2 0x13028da 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x224d 0x21b5)
terminate called throwing an exception(lldb) 

: , ?

: :

- 10 scene1-10,

- segue 11- sceneRandomizer ( segues)

-Connect 10 segues from sceneRandomizer 1-10 ( segue1-10)

- "sceneRandomizer", 1-10
( , , ... )

, , , .

, , segue ?




- . , "round-about", , , , :

.h .m , , :

.h :

#import <UIKit/UIKit.h>

@interface scene1 : UIViewController

- (IBAction) randomButton;

@end

.m :

#import "scene1.h"

@interface scene1 ()

@end

@implementation scene1

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)randomButton
{
    int i = arc4random() % 10 + 1;
    NSString *segueIdentifier = [NSString stringWithFormat:@"segue%d", i];
    [self performSegueWithIdentifier:segueIdentifier sender:self];

}- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end

:

, - 11

  • "startPage" "scene1-10"

  • 1.h .m (, ) StartPage.h
    StartPage.m

  • 11 (StartPage)

  • 10 segues, 1 StartPage 10 ,

  • 10 segues 1, 1, 1 segue2-10 ( , ) , note segue scene1 scene1, segue scene1 scene2 segue1.

  • 9

. . StartPage. (scene1-10), .

- , . 110 , 11 ...... .

:

, segue. , segues 5, 2 segues segue2 segue3. 5, segue3, , 5 segue segue3. , โ€‹โ€‹, , segue3, 5.

- - , , , . , :)

+3
3

randomButton . , .h:

- (IBAction)randomButton:(id)sender;

.m :

- (IBAction)randomButton
{
    int i = arc4random() % 10;
    // ...
}

, segue, i:

- (IBAction)randomButton
{
    int i = arc4random() % 10 + 1;
    NSString *segueIdentifier = [NSString stringWithFormat:@"segue%d", i];
    [self performSegueWithIdentifier:segueIdentifier sender:self];
}

, , , i 1 10. 0 9.

+1

, , randomButton, .

-(void)randomButton:(id)sender;, -(void)randomButton;

. , .

+2

I used to do something like this using modal viewControllers from a single parent. Pressing the button will tell the parent element rejectModalViewController, and then in the parent view, WillAppear will generate a random number and pushModalViewController. I did all this with xibs, so I'm not sure how you will do this using modal segments. If you find out, let us know.

0
source

All Articles