gpt4 book ai didi

ios - UIButton 在 iOS7 中点击时不显示突出显示 - Swift

转载 作者:行者123 更新时间:2023-11-28 13:13:45 26 4
gpt4 key购买 nike

来自 this他们说这是 ios 7 和 8 中的一个错误 - UITableViewCell 中的按钮在点击时不会更改为突出显示。在这里,我在 Objective-C 中发布了一个答案:

创建自定义 UITableView 子类和自定义 UITableViewCell 子类。

使用此示例 UITableView 的 initWithFrame:

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];

if (self)
{
// iterate over all the UITableView's subviews
for (id view in self.subviews)
{
// looking for a UITableViewWrapperView
if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewWrapperView"])
{
// this test is necessary for safety and because a "UITableViewWrapperView" is NOT a UIScrollView in iOS7
if([view isKindOfClass:[UIScrollView class]])
{
// turn OFF delaysContentTouches in the hidden subview
UIScrollView *scroll = (UIScrollView *) view;
scroll.delaysContentTouches = NO;
}
break;
}
}
}
return self;
}

使用此示例 UITableViewCellinitWithStyle:reuseIdentifier:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self)
{
// iterate over all the UITableViewCell's subviews
for (id view in self.subviews)
{
// looking for a UITableViewCellScrollView
if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewCellScrollView"])
{
// this test is here for safety only, also there is no UITableViewCellScrollView in iOS8
if([view isKindOfClass:[UIScrollView class]])
{
// turn OFF delaysContentTouches in the hidden subview
UIScrollView *scroll = (UIScrollView *) view;
scroll.delaysContentTouches = NO;
}
break;
}
}
}

return self;
}

但是我不能用 Swift 编写。有一些问题:

1)我做不到

self = super.init(style: style, reuseIdentifier: reuseIdentifier) 

错误:无法在方法中分配给'self'

2) 在 Swift 中,我做不到

view.class

在 objective-c 中:

[view class]

我已经搜索了几个小时,但仍然找不到我想要的。

谁能用 Swift 回答这个问题?

最佳答案

在 Swift 中,要调用父类(super class)的指定初始化程序,而不是调用 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier],您只需使用 super.init(style: style, reuseIdentifier : 重用标识符)

关于ios - UIButton 在 iOS7 中点击时不显示突出显示 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30166729/

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