gpt4 book ai didi

objective-c - 关于自定义类初始化的 EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-02 22:12:37 26 4
gpt4 key购买 nike

我写了下面的类:

.h:

#import <Foundation/Foundation.h>
@class TDLPaneViewController;

@interface TDLSubViewController : NSObject

@property (nonatomic, strong) IBOutlet UIView* view;
@property (nonatomic, strong) TDLPaneViewController* paneViewController;

- (id) initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;

- (void)viewWillAppear:(BOOL)animated;
- (void)viewDidAppear:(BOOL)animated;
- (void)viewWillDisppear:(BOOL)animated;
- (void)viewDidDisppear:(BOOL)animated;

@end

.m:

#import "TDLSubViewController.h"

@interface TDLSubViewController ()
{
UIView *view;
}

@property (nonatomic, strong) NSString* nibName;
@property (nonatomic, strong) NSBundle* nibBundle;

@end

@implementation TDLSubViewController

@synthesize paneViewController, view;
@synthesize nibName, nibBundle;

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super init];

if (self)
{
self.nibName = nibNameOrNil;
self.nibBundle = nibBundleOrNil;
}
}

- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"viewWillAppear:%i", animated);
}
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"viewDidAppear:%i", animated);
}
- (void)viewWillDisppear:(BOOL)animated
{
NSLog(@"viewWillDisppear:%i", animated);
}
- (void)viewDidDisppear:(BOOL)animated
{
NSLog(@"viewDidDisppear:%i", animated);
}

@end

显示另一个 View 时出现错误: - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];

     TDLTestSubViewController* subView = [[TDLTestSubViewController alloc] initWithNibName:@"TDLTestSubViewController" bundle:nil] ;

[self pushSubViewController:nil animated:YES leftSide:YES];

}

TDLTestSubViewController 是 TDLSubViewController 的子类。

如果我使用 UIViewController 而不是 TDLTestSubViewController,一切正常,如果我关闭 ARC,它也可以。所以我认为问题出在 TDLSubViewController 类中。请指出可能出了什么问题?

最佳答案

您的 initWithNibName:bundle: 方法在必须返回时不会返回 self

关于objective-c - 关于自定义类初始化的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15003268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com