2012-04-05 67 views
-1

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

我得到了一个水平滚动滚动视图,为垂直滚动添加了一个子视图,第二个子视图保存了我的按钮所在的视图控制器。

如果我点击那个按钮,我得到一个不良接入错误。 NSZombie给了我这个错误:

2012-04-05 14:26:06.924 SlideAppTest[44978:f803] * -[SubSlide1Hoofdstuk3 performSelector:withObject:withObject:]: message sent to deallocated instance 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; 
} 
+0

试试这个: @property(强,非原子)IBOutlet中的UIButton *按钮; – Nilesh 2012-04-05 12:40:39

+0

感谢您的回复,我仍然得到相同的错误:( – Joey 2012-04-05 14:23:38

+0

我添加了我的示例项目,如果你必须快速浏览一下,会很棒!谢谢 – Joey 2012-04-05 14:35:38

回答

0

看起来像你的问题不是在UIButton的,但UIScrollView的。你有财产申报是软弱的,它应该是强大的(或保留,如果你不尝试使用ARC)

+0

感谢您的回复,我尝试了两个选项,强大的和保留选项,两个选项都没有工作..我更新我的文章与项目文件,马比你可以快速看看这里出了什么问题?会很好! – Joey 2012-04-05 14:33:39