真的很希望你能帮助我!我有一个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;
}
试试这个: @property(强,非原子)IBOutlet中的UIButton *按钮; – Nilesh 2012-04-05 12:40:39
感谢您的回复,我仍然得到相同的错误:( – Joey 2012-04-05 14:23:38
我添加了我的示例项目,如果你必须快速浏览一下,会很棒!谢谢 – Joey 2012-04-05 14:35:38