gpt4 book ai didi

iphone - 如何修复 Receiver in message expression is an uninitialized value warning

转载 作者:行者123 更新时间:2023-11-28 22:52:46 24 4
gpt4 key购买 nike

对于创建 UIButton 的某些代码,我收到以下错误消息。我将如何初始化它以修复 Analyzer 警告我的错误:

逻辑错误:消息表达式中的receiver是一个未初始化的值

错误发生在粗体行

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UILabel *textLabel;
UILabel *detailTextLabel;
UIButton *button;

UIFont *cellFont = [UIFont boldSystemFontOfSize:10.0];
UIFont *detailCellFont = [UIFont fontWithName:@"Helvetica" size:8.0];

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

// Initialize API title UILabel
textLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
textLabel.tag = TITLE_TAG;
textLabel.font = cellFont;
[cell.contentView addSubview:textLabel];

// Initialize API description UILabel
detailTextLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
detailTextLabel.tag = DESCRIPTION_TAG;
detailTextLabel.font = detailCellFont;
detailTextLabel.textColor = [UIColor blackColor];
detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
detailTextLabel.numberOfLines = 0;
[cell.contentView addSubview:detailTextLabel];

// Initialize API button UIButton
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
[button setBackgroundImage:[[UIImage imageNamed:@"blueButton.png"]
stretchableImageWithLeftCapWidth:9 topCapHeight:9]
forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(apiButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
} else {
textLabel = (UILabel *)[cell.contentView viewWithTag:TITLE_TAG];
detailTextLabel = (UILabel *)[cell.contentView viewWithTag:DESCRIPTION_TAG];
// For the button cannot search by tag since it is not constant
// and is dynamically used figure out which button is clicked.
// So instead we loop through subviews of the cell to find the button.
for (UIView *subview in cell.contentView.subviews) {
if([subview isKindOfClass:[UIButton class]]) {
button = (UIButton *)subview;
}
}
}

CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);

// The API title
NSString *cellText = [[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"title"];
CGSize labelSize = [cellText sizeWithFont:cellFont
constrainedToSize:constraintSize
lineBreakMode:UILineBreakModeWordWrap];
textLabel.frame = CGRectMake(20, 2,
(cell.contentView.frame.size.width-40),
labelSize.height);
textLabel.text = cellText;

// The API description
NSString *detailCellText = [[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"description"];
CGSize detailLabelSize = [detailCellText sizeWithFont:detailCellFont
constrainedToSize:constraintSize
lineBreakMode:UILineBreakModeWordWrap];
detailTextLabel.frame = CGRectMake(20, (labelSize.height + 4),
(cell.contentView.frame.size.width-40),
detailLabelSize.height);
detailTextLabel.text = detailCellText;


// The API button
CGFloat yButtonOffset = labelSize.height + detailLabelSize.height + 15;
**button.frame = CGRectMake(20, yButtonOffset, (cell.contentView.frame.size.width-40), 44);**
[button setTitle:[[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"button"]
forState:UIControlStateNormal];
// Set the tag that will later identify the button that is clicked.
button.tag = indexPath.row;


return cell;
}

谢谢你的帮助

最佳答案

您是否在代码中的任何地方做过类似的事情?

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];

(类型也可能是 UIButtonRoundRect)

...或者这个:

UIButton* button = [[UIButton alloc] initWithType:UIButtonTypeCustom];

关于iphone - 如何修复 Receiver in message expression is an uninitialized value warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11520253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com