Take the 2-minute tour ×

First Controller's code:

 optionscontroller =  [[OptionsViewController alloc] init ];

 [optionscontroller setupSocket];

Second controller's code:

- (void)setupSocket
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self      delegateQueue:dispatch_get_main_queue()];

NSError *error = nil;

if (![udpSocket bindToPort:0 error:&error])
    //  [self logError:FORMAT(@"Error binding: %@", error)];
if (![udpSocket beginReceiving:&error])
    //  [self logError:FORMAT(@"Error receiving: %@", error)];

isRunning = YES;
NSLog(@"Udp Echo server started on port %hu", [udpSocket localPort]); }

One of actions:

- (IBAction)testbutton:(id)sender {

NSString *host = @"";
if ([host length] == 0)

    NSLog(@"Address required");


NSString *msg = @"hi";
if ([msg length] == 0)
    //[self logError:@"Message required"];

NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
[udpSocket enableBroadcast:YES error:nil ];
[udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:0];



When i call "setupSocket" from first controller it starts, but when i go to OptionsViewController and click the button - nothing happens, it's connoted right and it works, when i call "setupSocket" from second controller's "view did load function" everything works okay, why???

So if initialize some methods not from target view controller this methods doesn't work. i can't understand how it may happen?

share|improve this question
How do you go the the OptionsViewController? I am pretty sure you use a different instance than the one you used in [optionscontroller setupSocket];. Also, what do you mean by action method doesn't work? can you be more specific? –  sch Apr 12 '12 at 18:03
i just tap a tab bar icon –  Horhe Garcia Apr 12 '12 at 18:47

1 Answer 1

If you are using a XIB with interface builder you need to make sure that you wire the button up to it's action. Do this by right clicking and dragging from your button to your file's owner in the Interface Builder.

Oh also, you need to optionscontroller = [[OptionsViewController alloc] initWithNibName:@"YOURNIBNAMEHERE"];

If you are creating it programmatically (which if you're using IBAction you should not be) then you would use this:


Read here:


share|improve this answer
If you are using a XIB file you will have to load it at some point. IBAction indicates you're using Interface Builder and a XIB file probably. –  Inturbidus Apr 12 '12 at 18:41

Your Answer


