0

我可以将文本添加到我的UITableView,但是当我尝试添加到detailTextLabel某个曾经是 a 的字符串时,NSDate应用程序崩溃并显示:

'NSInvalidArgumentException', reason: '-[__NSDate isEqualToString:]:
 unrecognized selector sent to instance 0x8383690'

我可以添加一个普通的假人NSStringdetailTextLabel所以我不明白。有什么帮助吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }


    NSString* temp = [biggerDateA objectAtIndex:indexPath.row];


    cell.textLabel.text = [bigA objectAtIndex:indexPath.row];
    //cell.detailTextLabel.text = [biggerDateA objectAtIndex:indexPath.row];
    //cell.detailTextLabel.text = @"Date Goes here";
    cell.detailTextLabel.text = temp;

    [bigA retain];
    //[biggerDateA retain];
    return cell;
}
4

2 回答 2

4

问题是这一行:

NSString* temp = [biggerDateA objectAtIndex:indexPath.row];

即使声明这是一个,重要的是它NSString什么。它是什么,是一个.NSDate

你需要它是一个NSString,但是你必须显式地转换它,可能是通过一个NSDateFormatter.

于 2013-05-16T18:57:57.750 回答
2

Try using following code by converting to NSDate to NSString.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    NSDate* date = [biggerDateA objectAtIndex:indexPath.row];
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"MMM dd, yyyy HH:mm"];
    NSString *temp = [format date];
    cell.textLabel.text = [bigA objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = temp;
    [bigA retain];
    //[biggerDateA retain];
    return cell;
}
于 2013-05-16T19:03:00.473 回答