2012-03-05 52 views
0

没有编译器错误,但无法追踪到我的类的实例方法。我很确定我只是没有正确地设置它,但我想这可能是一些模糊的配置(希望不是)。我的自定义类在UIViewController中被破坏,无法追踪到它,没有编译器错误

我对这些类的调用不能被追踪到(只显示汇编程序),ATLCalCellList类中的断点(即init,load,clear)永远不会执行。

的UIViewController头:

// 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 

回答

1

我认为问题在于你打电话给init的东西还没有真正分配过。本质上,你的代码告诉应用程序去self.calCellList碰巧指向的任何内存中的任意位置,将它当作一个对象,并发送一个init消息给它。当然,这可能会导致各种问题。

它可以更好地工作,如果你这样做:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

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

另外请注意,如果你这样做:

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

...那么你并不需要同时声明后盾伊娃的领域。具体而言,这是多余的:

ATLCalCellList* calCellList ; 

@synthesize的属性,将自动为您要生成的相同名称的背衬的ivar。你所拥有的代码基本上是两次宣布伊娃,这是无害的,但没有必要。

编辑:刚接手你的代码仔细一看,你似乎正在在其他地方犯同样的错误,以及:

self.calListArray = [calListArray init] ; 

如上所述,这是不行的。您无法通过调用init来初始化未分配的变量。您需要alloc实例,然后在该实例上调用init。像:

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

感谢信AROTH ...这奏效了,有时候你看不出它在自己的代码......在一定程度上,我知道的是,类应该初始化实例,但我不知何故认为ARC意味着不再有ALLOC。我查看了这个以及看到ARC只是自动处理释放代码,但你仍然应该做的分配。 无论如何,我完全按照您的指示进行了更改。我放弃了无关的变量声明。 (我曾经想过SYNTHESIZE只创建SETters。)真的很感激你的快速反应,带来一些不必要的编码苦难到底! – 2012-03-05 07:26:38

相关问题