-1

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

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

plist 中的partyTime 设置为“日期”格式。它会崩溃。如果我将日期更改为“字符串”并且没有问题。如果我将其保留为日期,我会在 Main.m autoreleasepool 收到错误

@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;
}
4

1 回答 1

0

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

如果您将 NSDate 对象传递给它,它不知道如何处理它,因此会崩溃。

于 2013-09-08T07:22:51.500 回答