initWithStyle:CGRectZero将'const CGRect'发送到不兼容类型的参数

时间:2014-09-28 18:01:12

标签: ios objective-c uitableview

我正在处理这段代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:CGRectZero reuseIdentifier:nil] autorelease];
}
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

并首先更换

initWithFrame: 

initWithStyle: 
上面的

,因为我收到initWithFrame:reuseIdentifier deprecated错误。

但是,现在我收到了一个新错误:

Sending 'const CGRect' (aka 'const struct CGRect') to parameter of incompatible type 'UITableViewCellStyle' (aka 'enum UITableViewCellStyle'). 

此错误主要针对上面CGRectZero中的initWithStyle:CGRectZero

我已经搜索过,无法解决这个问题。有人知道如何解决这个问题吗? 提前致谢! :)

1 个答案:

答案 0 :(得分:0)

style参数必须是UITableViewCellStyle enumeration values之一:

typedef enum : NSInteger {
   UITableViewCellStyleDefault ,
   UITableViewCellStyleValue1 ,
   UITableViewCellStyleValue2 ,
   UITableViewCellStyleSubtitle 
} UITableViewCellStyle;

如果仔细观察,您会发现CGRectZero不在列表中。通常,当您更改语句以发送不同的消息时,您应该需要更改作为消息参数传递的值。