2

我已经阅读了有关多种方法的其他问题,但仍然不知道如何修复我的代码。对于这方面的帮助,我将不胜感激。我在发生错误的语句周围 放了一个* 。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 
      (NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"eventCell";
    EQCalendarCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
       cell = [[EQCalendarCell alloc] initWithStyle:UITableViewCellStyleDefault
      reuseIdentifier:CellIdentifier];
    }
    cell.titleLabel.text = [[self.eventsList objectAtIndex:indexPath.row] title];

    cell.locationLabel.text = [[self.eventsList objectAtIndex:indexPath.row] location];

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat: @"dd-MM-yy HH:mm"];
    NSString *startDateString = [df stringFromDate:[[self.eventsList
    objectAtIndex:indexPath.row] startDate]];

    cell.startDateLabel.text = startDateString;

    NSString *endDateString = [df stringFromDate:[[self.eventsList
    objectAtIndex:indexPath.row] endDate]];


    cell.endDateLabel.text = endDateString;

    return cell;
    }

提前感谢您的帮助。

4

4 回答 4

7

转换从集合中检索对象的结果self.eventsList应该可以解决问题。例如:

cell.locationLabel.text = [((MyClassName *)[self.eventsList objectAtIndex:indexPath.row]) location];

替换MyClassName为集合中类的名称。

于 2014-04-14T11:04:17.740 回答
3

您需要转换[self.eventsList objectAtIndex:indexPath.row]为相关类型,以便编译器知道您正在处理的数据类型。

如果没有看到你的 self.eventList 列表是如何填充的,就不可能准确地告诉你解决方案,但是你的行应该用这样的东西替换(为了清楚起见分成两行,但你可以使用强制转换而不是变量来保持它在一条线上)

MyEventClass *event = [self.eventsList objectAtIndex:indexPath.row];
cell.locationLabel.text = [event location];
于 2014-04-14T11:04:33.970 回答
1

您需要强制转换 EKEvent 类。这将解决您的问题...

EKEvent *event = [self.eventlist objectAtIndex:indexPath.row];
NSString *placeStr=[event location];
于 2014-06-11T10:09:42.027 回答
0

在一种情况下,如果创建对象的工厂方法具有返回类型“id”,那么编译器将检查所有类中的方法签名。如果编译器在多个类中发现相同的方法签名,则会引发问题。因此,将返回类型“id”替换为“特定类名”。

于 2014-10-21T10:43:46.157 回答