gpt4 book ai didi

iphone - 我的自定义类在 UIViewController 内部损坏,无法跟踪它,没有编译器错误

转载 作者:行者123 更新时间:2023-11-29 04:46:32 25 4
gpt4 key购买 nike

没有编译器错误,但无法跟踪我的类的实例方法。我很确定我只是没有正确设置它,但我想这可能是一些晦涩的配置(希望不是)。

无法跟踪我对类的调用(仅显示汇编程序),并且 ATLCalCellList 类中的断点(即在 init、load、clear 处)永远不会执行。

UIViewController header :

//  ATLCalendarViewController.h
#import <UIKit/UIKit.h>
#import "ATLCalCellList.h"

@interface ATLCalendarViewController : UIViewController {
ATLCalCellList* calCellList ;
}
@property (nonatomic, strong) ATLCalCellList* calCellList ;

- (IBAction)btnTestLoadListPress:(id)sender;
- (void) refreshCalCellList ;
@end

主文件:

//  ATLCalendarViewController.m

#import "ATLCalendarViewController.h"
@implementation ATLCalendarViewController
@synthesize calCellList ;

- (void)viewDidLoad {
[super viewDidLoad];
// Custom initialization
[self.calCellList init] ;
}

- (IBAction)btnTestLoadListPress:(id)sender
{
[self refreshCalCellList] ;
}

- (void) refreshCalCellList
{
**//================================== PROBLEM ========================================**
// BREAKPOINTS ON THE 4 LINES BELOW GET CALLED, BUT CAN'T TRACE INTO THE METHOD CODE
// TRACE INTO ON ANY OF THESE SHOWS ASSEMBLER
// IT LOOKS LIKE THE CALLED CODE IN THE METHODS IS NOT BEING EXECUTED
[self.calCellList clear] ;
self.calCellList.calListCount = 0 ;
self.calCellList.calListDate = [NSDate date] ;
[self.calCellList load] ;
}

@end

calCellList 的类头文件是:

//  ATLCalCellList.h
#import <Foundation/Foundation.h>
#import "ATLCalCellData.h"

@interface ATLCalCellList : NSObject {

NSMutableArray *calListArray ;
NSInteger calListCount ;
NSDate *calListDate ;
BOOL calListSimulate ;
}

// PROPERTIES
@ property(nonatomic, strong) NSMutableArray *calListArray ;
@ property(nonatomic) NSInteger calListCount ;
@ property(nonatomic, strong) NSDate *calListDate ;
@ property(nonatomic) BOOL calListSimulate ;

// METHODS
- (id) init ;
- (BOOL) load ;
- (BOOL) save ;
- (void) clear ;
- (void) addCell: (ATLCalCellData *) calCellData ;
- (void) removeCell: (ATLCalCellData *) calCellData ;

如果您需要查看完整的类实现,这里是其中的大部分内容:

//  ATLCalCellList.m
#import "ATLCalCellList.h"
@implementation ATLCalCellList

@synthesize calListArray ;
@synthesize calListCount ;
@synthesize calListDate ;
@synthesize calListSimulate ;

- (id) init
{
self = [super init] ;

self.calListArray = nil ;
self.calListArray = [calListArray init] ;
self.calListDate = [NSDate date] ;

return self ;
}

- (BOOL) load
{
// load data for one day
ATLCalCellData* newCell ;
if ([newCell init]) {
newCell.calCellDate = self.calListDate ;
newCell.calCellHour = x ;
newCell.calCellMinute = 0 ;
newCell.calCellTitle = @"Appt with Destiny" ;
newCell.calCellLocation = @"Atlas World HQ" ;
[newCell.calCellAlliesIDList addObject: @"333000333" ] ;
[newCell.calCellAlliesNameList addObject: @"Joe Chicago"] ;
newCell.calCellDurationMinutes = 60 ;
newCell.calCellAlarm1AdvanceMinutes = 30 ;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setHour:0];
[offsetComponents setMinute: newCell.calCellAlarm1AdvanceMinutes];
newCell.calCellAlarm1Datetime =
[gregorian dateByAddingComponents:offsetComponents toDate:
newCell.calCellAlarm1Datetime options:0];
}
}
}
}
} else {
// load the cells from the actual database:
// #OPENTASK

// end
}
return TRUE ;
}

- (BOOL) save
{
// save data for one day
return TRUE ;
}


- (void) clear {
// Clear the daylist array

self.calListArray = nil ;
[self.calListArray init];
}

- (void) addCell: (ATLCalCellData *) calendarCell {
[self.calListArray addObject: calendarCell];
}

- (void) removeCell: (ATLCalCellData *) calendarCell {
// Find and remove the passed in cell from the array:
// #TBD Locate the cell with the datetime and userid, then delete it
//
}

@end

最佳答案

我认为问题在于您正在对尚未实际分配的内容调用 init 。本质上,您的代码是告诉应用程序转到 self.calCellList 恰好指向的内存中的任何随机位置,将其视为对象,并向其发送一条 init 消息它。当然,这可能会导致各种问题。

如果您这样做,效果可能会更好:

- (void)viewDidLoad  {
[super viewDidLoad];

// Custom initialization
calCellList = [[ATLCalCellList alloc] init] ;
}

另请注意,如果您这样做:

@property (nonatomic, strong) ATLCalCellList* calCellList ;
//...
@synthesize calCellList ;

...那么您不需要为该字段声明一个支持 ivar。具体来说,这是多余的:

ATLCalCellList* calCellList ;

当您@synthesize该属性时,将自动为您生成一个同名的支持ivar。您所拥有的代码本质上是声明 ivar 两次,这是无害但不必要的。

编辑:刚刚仔细查看了您的代码,您似乎在其他地方也犯了同样的错误:

self.calListArray = [calListArray init] ;

如上所述,这不会起作用。您无法通过调用 init 来初始化未分配的变量。您需要分配一个实例,然后在该实例上调用init。喜欢:

self.calListArray = [[NSMutableArray alloc] init];

关于iphone - 我的自定义类在 UIViewController 内部损坏,无法跟踪它,没有编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9562029/

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