真的希望你能帮助我!我对Subviews有一个奇怪的问题。我试图在我的一个Subviews中做一个简单的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;
}
答案 0 :(得分:0)
看起来您的问题不在UIButton中,而是在UIScrollView中。您将该属性声明为弱,它应该是强大的(或者如果您不尝试使用ARC则保留)