开发者

Using UIButtons to open a different .nib

开发者 https://www.devze.com 2023-03-19 01:12 出处:网络
something isn\'t working right and i can\'t work out why this isn\'t working to load my other nib, this currently works

something isn't working right and i can't work out why this isn't working to load my other nib, this currently works

#pragma mark - Flipside View

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showInfo:(id)sender
{    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

whilst i've done the exact same thing here on the same MainViewController.m and had no success whilst doing it

#pragma mark - News View

- (void)newsViewControllerDidFinish:(NewsViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizont开发者_Go百科al;
    [self presentModalViewController:controller animated:YES];
}

so i think there is something wrong with my header file which looks like this

    #import "FlipsideViewController.h"
#import "NewsViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, NewsViewControllerDelegate>

- (IBAction)showInfo:(id)sender;
- (IBAction)showNews:(id)sender;

@end

I can't work out why it's not working, any help would be appreciated.

Error from output:

This GDB was configured as "x86_64-apple-darwin".Attaching to process 2147. 2011-07-08 12:24:09.845 Danny[2147:ef03] -[NewsViewController setDelegate:]: unrecognized selector sent to instance 0x68a62b0 2011-07-08 12:24:09.847 Danny[2147:ef03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NewsViewController setDelegate:]: unrecognized selector sent to instance 0x68a62b0' * First throw call stack: (0xf8a600 0x112252e 0xf8d550 0xeeb4cf 0xeeb292 0x2a36 0xf8bd78 0x18cc5 0x18c5a 0xbdbd4 0xbe09d 0xbd368 0x3e004 0x3e22d 0x24990 0x181a7 0x1369886 0xf59d11 0xebbc9b 0xeba4b1 0xeb993c 0xeb9868 0x1367fef 0x13680b4 0x160c4 0x2009 0x1f75) terminate called throwing an exceptionsharedlibrary apply-load-rules all Current language: auto; currently objective-c (gdb)


What is the delegate method for the view controller? Check if the declaration of the delegate method is the same. Make sure you have set the delegates properly


Try this:

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

And in the News View, instead of writing

[self.delegate newsViewControllerDidFinish:self];

you should write:

[self dismissModalViewControllerAnimated:YES];

That should solve your problem. I don't see much point in writing extra delegates, they don't usually give you any advantages (in scenarios like this one), when you can just have a view controller dismiss itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消