Pregunta

I read on other stack overflow posts that this error is cause due to improper memory management but I cant figure out where that problem is being caused. I am receiving the following error:

Debug Image

2014-03-23 12:47:16.337 Cazenovia High School[11810:60b] -[iPhoneFirstPageView Twitter]: unrecognized selector sent to instance 0x10944bc10
2014-03-23 12:47:16.342 Cazenovia High School[11810:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[iPhoneFirstPageView Twitter]: unrecognized selector sent to instance 0x10944bc10'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010194c495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001016ab99e objc_exception_throw + 43
    2   CoreFoundation                      0x00000001019dd65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010193dd8d ___forwarding___ + 973
    4   CoreFoundation                      0x000000010193d938 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000100259f06 -[UIApplication sendAction:to:from:forEvent:] + 80
    6   UIKit                               0x0000000100259eb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
    7   UIKit                               0x0000000100336880 -[UIControl _sendActionsForEvents:withEvent:] + 203
    8   UIKit                               0x0000000100335dc0 -[UIControl touchesEnded:withEvent:] + 530
    9   UIKit                               0x000000010057d6f7 _UIGestureRecognizerUpdate + 5149
    10  UIKit                               0x0000000100290a15 -[UIWindow _sendGesturesForEvent:] + 928
    11  UIKit                               0x00000001002916d4 -[UIWindow sendEvent:] + 909
    12  UIKit                               0x000000010026929a -[UIApplication sendEvent:] + 211
    13  UIKit                               0x0000000100256aed _UIApplicationHandleEventQueue + 9579
    14  CoreFoundation                      0x00000001018dbd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x00000001018db5f2 __CFRunLoopDoSources0 + 242
    16  CoreFoundation                      0x00000001018f746f __CFRunLoopRun + 767
    17  CoreFoundation                      0x00000001018f6d83 CFRunLoopRunSpecific + 467
    18  GraphicsServices                    0x0000000103ac3f04 GSEventRunModal + 161
    19  UIKit                               0x0000000100258e33 UIApplicationMain + 1010
    20  Cazenovia High School               0x0000000100002ef3 main + 115
    21  libdyld.dylib                       0x0000000101fe45fd start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

My code is included below, you can also find my project on http://github.com/rileylloyd24/cazenovia

I have a ScrollView in my Storyboard (ViewController) with an embedded nav controller (navigationController). I also have 2 nibs, one of which (iPhoneFirstPageView) I am trying to segue to another nib (TwitterViewController).

ViewController.h

#import "ViewController.h"
#import "TwitterViewController.h"
#import "iPhoneFirstPageView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Set up View for scrollview with nav controller
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"Cazenovia Central School District";
    self.bottomBar.backgroundColor = [UIColor colorWithRed:9.0f/255.0f green:49.0f/255.0f blue:102.0f/255.0f alpha:1.0f];

    //do some set up on the scrollview
    self.theScrollView.pagingEnabled = YES;
    self.theScrollView.showsHorizontalScrollIndicator = NO;
    self.theScrollView.showsVerticalScrollIndicator = NO;

    //Load the nibs to be paged through
    //NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"iphoneFirstPageView" owner:self options:nil];
    //UIView *firstPageView = (UIView *)[nibArray objectAtIndex:0];

    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"iphoneFirstPageView" owner:self options:nil];
    iPhoneFirstPageView *firstPageView = (iPhoneFirstPageView *)[nibArray objectAtIndex:0];
    [firstPageView.twitterButton addTarget:self action:@selector(executeSegue) forControlEvents:UIControlEventTouchUpInside];

    NSArray *nibArray2 = [[NSBundle mainBundle] loadNibNamed:@"iPhoneSecondPage" owner:self options:nil];
    UIView *secondPageView = (UIView *)[nibArray2 objectAtIndex:0];

    NSArray *pageArray = @[firstPageView, secondPageView];

    //Add each view to the scroll view
    for(int i=0; i<pageArray.count; i++){
        CGRect frame;
        frame.origin.x = self.theScrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.theScrollView.frame.size;

        UIView *subview = [[UIView alloc] initWithFrame:frame];
        [subview addSubview:[pageArray objectAtIndex:i]];
        [self.theScrollView addSubview:subview];
    }
    self.theScrollView.contentSize = CGSizeMake(self.theScrollView.frame.size.width * pageArray.count, self.theScrollView.frame.size.height);
    self.theScrollView.delegate = self;
    self.thePageControl.numberOfPages = pageArray.count;
    //Twitter segue
}


-(void)executeSegue
{
    TwitterViewController *newController = [[TwitterViewController alloc] initWithNibName:@"TwitterViewController" bundle:nil];
    [self.navigationController pushViewController:newController animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)sender {
    CGFloat pageWidth = self.theScrollView.frame.size.width;
    int page = floor((self.theScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.thePageControl.currentPage = page;
}
¿Fue útil?

Solución

I have looked your code and you need to remove the outlet in story board from twitter icon button.You connected that previously. You have commented previous outlet method -(IBAction)Twitter but you also need to remove touchupinside action outlet from storyboard.Just go iphoneFirstPageView.xib and right click on twitter button and remove action outlet for Twitter.

For another problem in -(void)executeSegue

You are loading whole viewcontroller from xib so use TwitterViewController *newController = [[[NSBundle mainBundle] loadNibNamed:@"TwitterViewController" owner:self options:nil] objectAtIndex:0]; instead of initWithNibName and remove the fileowner outlet for view.Then Everything will work fine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top