【问题标题】:initWithStyle:CGRectZero sending 'const CGRect' to parameter of incompatible typeinitWithStyle:CGRectZero 将“const CGRect”发送到不兼容类型的参数
【发布时间】:2014-09-28 18:01:11
【问题描述】:

我正在处理这段代码:

- (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'). 

此错误专门指向上面initWithStyle:CGRectZero 中的CGRectZero

我已经搜索过,但无法弄清楚这一点。有谁知道如何解决这个问题?
提前致谢! :)

【问题讨论】:

  • 您是否真的阅读过错误信息并试图理解它???? (你看过 UITableViewCell 的文档了吗????)

标签: ios objective-c uitableview


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    相关资源
    最近更新 更多