我在向下滚动UITableView时遇到了iPhone应用崩溃的问题。我将NSZombieEnabled设置为YES,并发现我用来填充表格的NSArray以某种方式得到处理。NSArray早期发布
#import "RootViewController.h"
@implementation RootViewController
@synthesize flashsets;
- (void)viewDidLoad
{
//Unrelated code removed from this post
NSString *listofsetsstring = [[NSString alloc]
initWithContentsOfFile:pathtosetsdata
encoding:NSUnicodeStringEncoding
error:&error];
flashsets = [listofsetsstring componentsSeparatedByString:@"\n"];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [flashsets count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSLog(@"IndexPath.row = %i", indexPath.row);
cell.textLabel.text = [flashsets objectAtIndex:indexPath.row]; <<<< CRASH HERE!!
return cell;
}
@end
我在粗体行收到message sent to deallocated instance 0x4ebae20
。在我的.h中,我使用了@property (nonatomic, retain) NSArray *flashsets;
,我认为保留部分应该避免释放。
我该如何避免这样做?
谢谢!我将不得不记住将来使用[self variablename]。 – Cole