当原型单元格使用 PLIST 中的日期时自动发布时出错



>当我使用自定义单元格填充我的表视图时,当它仅使用来自 plist 的字符串时,我没有问题。 但是当我尝试填充时

cell.detailTextLabel.text = [partyTime objectAtIndex:indexPath.row];

plist中的派对时间设置为"日期"格式。 它会崩溃。 如果我将日期更改为"字符串",没问题。如果我将其保留为日期,我会在 Main.m 自动发布池中收到错误

@autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([BaliPartyAppDelegate class]));
    }

我需要释放 NSDate 吗? 和图像

? 如何?

这是我到目前为止的代码

 NSArray *parties;
    NSArray *searchResults;
    NSArray *tableData;
    NSArray *thumbnails;
    NSArray *partyTime;
}
@synthesize tableView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Initialize table data
   // parties = [NSArray arrayWithObjects:@"Snoop Dog", @"AVICII", @"Frenzal Rhomb", @"Someone else", @"Cool Band", @"Lady Boys",  nil];
    // Find out the path of recipes.plist
    NSString *path = [[NSBundle mainBundle] pathForResource:@"parties" ofType:@"plist"];
    // Load the file content and read the data into arrays
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    parties = [dict objectForKey:@"PartyName"];
    thumbnails = [dict objectForKey:@"Thumbnail"];
    partyTime = [dict objectForKey:@"PartyTime"];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [searchResults count];
    } else {
        return [parties count];
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"PartyCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
   }
   if (tableView == self.searchDisplayController.searchResultsTableView) {
        cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
   } else {
       cell.textLabel.text = [parties objectAtIndex:indexPath.row];
       cell.detailTextLabel.text = [partyTime objectAtIndex:indexPath.row];
       //cell.imageView.image = [thumbnails objectAtIndex:indexPath.row];

    }
    return cell;
}

假设您使用的是ARC(因为我在您的代码片段中没有看到任何其他对" release"的调用),请不要担心发布任何内容。 您看到的崩溃与您分配给单元格的标签" .text"属性有关。UILabel的".text"属性只能接受NSString对象。

如果你给它传递一个NSDate对象,它不知道如何处理它,因此崩溃。

最新更新