提问人:user3331154 提问时间:4/14/2014 更新时间:10/21/2014 访问量:3665
发现名为“location”的多个方法的结果、参数类型或属性不匹配
Multiple methods named 'location' found with mismatched result, parameter type, or attributes
问:
我已经阅读了有关多种方法的其他问题,但仍然不知道如何修复我的代码。我将不胜感激。我在发生错误的语句周围放了一个 *。
- (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;
}
提前感谢您的帮助。
答:
7赞
bobnoble
4/14/2014
#1
强制转换从集合中检索对象的结果应该可以解决问题。例如:self.eventsList
cell.locationLabel.text = [((MyClassName *)[self.eventsList objectAtIndex:indexPath.row]) location];
替换为集合中类的名称。MyClassName
3赞
Clafou
4/14/2014
#2
您需要转换为相关类型,以便编译器知道您正在处理的数据类型。[self.eventsList objectAtIndex:indexPath.row]
如果不了解 self.eventList 列表的填充方式,就无法确切地告诉您解决方案,但您的行应该替换为这样的东西(为了清楚起见,分成两行,但您可以使用强制转换而不是变量将其保留在一行上)
MyEventClass *event = [self.eventsList objectAtIndex:indexPath.row];
cell.locationLabel.text = [event location];
1赞
Gopesh Gupta
6/11/2014
#3
您需要强制转换 EKEvent 类。这将解决您的问题...
EKEvent *event = [self.eventlist objectAtIndex:indexPath.row];
NSString *placeStr=[event location];
0赞
Praveen Matanam
10/21/2014
#4
在一种情况下,如果创建对象的工厂方法的返回类型为“id”,则编译器将检查所有类中的方法签名。如果编译器在多个类中找到相同的方法签名,则会引发问题。因此,将返回类型“id”替换为“特定类名”。
评论