我的 iPhone 应用程序在从 UITableView 委托方法之一访问实例变量时崩溃了。我想我会保留它,所以我不明白为什么我无法毫无问题地访问它。
这是我的 .h 文件
#import <Foundation/Foundation.h>
#import "AlertSummaryCell.h"
#import "AlertDetailViewController.h"
@interface AlertSummaryTableViewController : UITableViewController {
NSDictionary *alerts;
NSString *alertKind;
}
@property (nonatomic, 保留) NSDictionary *alerts; @property (nonatomic, 保留) NSString *alertKind;
@结尾
在我的 .m 中,应用程序在第一次 NSLog 调用时终止:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"AlertSummaryTableViewController.numberOfRowsInSection entered");
NSLog(@" alerts description = %@", [alerts description]);
// To know how many alert summaries we have, get the value for count out of the input dictionary
int theCount = [[alerts objectForKey:@"count"] intValue];
NSLog(@" Going to return %d",theCount);
return theCount;
}
我错过了什么???
viewDidLoad 方法完全没有问题:
- (void)viewDidLoad {
NSLog(@"AlertSummaryTableViewController.viewDidLoad entered");
NSLog(@" alerts description = %@", [alerts description]);
// We want the View title to include the alert count
// To know how many alert summaries we have, get the value for count out of the input dictionary
int theCount = [[alerts objectForKey:@"count"] intValue];
// Now construct the title text and set our views title to it
NSString *myTitle = [[NSString alloc] initWithFormat:@"%@ Alerts (%d)",alertKind,theCount];
[self setTitle: myTitle];
// Memory cleanup
[myTitle release];
[super viewDidLoad];
}