-1

真的希望你能帮助我!我对子视图有一个奇怪的问题。我试图在我的一个子视图中做一个简单的 IBAction,但是一旦我点击我的按钮,它就会给我一些内存错误。我试图将它添加到一个属性并合成按钮。

我有一个用于水平滚动的滚动视图,添加了一个用于垂直滚动的子视图,第二个子视图包含一个视图控制器,我的按钮所在的位置。

如果我单击该按钮,我会收到 BAD ACCESS 错误。NSZombie 给了我这个错误:

2012-04-05 14:26:06.924 SlideAppTest[44978:f803] * -[SubSlide1Hoofdstuk3 performSelector:withObject:withObject:]:消息发送到已释放实例 0x6c4bfe0

这是我的代码:

// RootSlideHoofdstuk3.h(垂直滚动)

#import <UIKit/UIKit.h>

@interface RootSlideHoofdstuk3 : UIViewController
<UIScrollViewDelegate>
{

}
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

// RootSlideHoofdstuk3.m(垂直滚动)

#import "RootSlideHoofdstuk3.h"
#import "SubSlide1Hoofdstuk3.h"

@implementation RootSlideHoofdstuk3
@synthesize scrollView = _scrollView;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _scrollView.pagingEnabled = YES;
    _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width,_scrollView.frame.size.height);
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.scrollsToTop = NO;    
    _scrollView.bounces = NO;
    _scrollView.delegate = self;

    SubSlide1Hoofdstuk3 *subslide1 = [[SubSlide1Hoofdstuk3 alloc] init];
    CGRect frame = self.view.frame;
    frame.origin.x = 0;
    frame.origin.y = 0;
    subslide1.view.frame = frame;
    [_scrollView addSubview:subslide1.view]; 
}

// SubSlide1Hoofdstuk3.h(幻灯片视图控制器)

#import <UIKit/UIKit.h>

@interface SubSlide1Hoofdstuk3 : UIViewController {
    UIButton *button;
}

@property (nonatomic, retain) IBOutlet UIButton *button;

@end

// SubSlide1Hoofdstuk3.m(幻灯片视图控制器)

#import "SubSlide1Hoofdstuk3.h"

@implementation SubSlide1Hoofdstuk3
@synthesize button = _button;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

}

-(IBAction)buttonActie {
    NSLog(@"Button clicked!");
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

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

1 回答 1

0

看起来您的问题不在 UIButton 中,而是在 UIScrollView 中。您将属性声明为弱,它应该是强的(如果您不尝试使用 ARC,则保留)

于 2012-04-05T13:35:20.793 回答