테이블보기의 한 셀에 전환 버튼이 있습니다. 이전에는 iOS 9에서 모든 것이 정상적으로 작동합니다. 클릭 전환 버튼을 클릭하면 액션 메소드가 실행됩니다.하지만 iOS 10으로 업데이트 한 후에는 액션 메소드가 호출되지 않습니다. 누구나 이와 비슷한 문제가 있습니까?iOS 10에서 UISwitch 동작이 작동하지 않습니다.
cell.m
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectZero];
[bgView setImage:[[UIImage imageNamed:@"customcell.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
[self setBackgroundView:bgView];
UIImageView *selectedBgView = [[UIImageView alloc] initWithFrame:CGRectZero];
[selectedBgView setImage:[[UIImage imageNamed:@"cellselect.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
[self setSelectedBackgroundView:selectedBgView];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 13, 250, 40)];
[nameLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleRightMargin];
[nameLabel setFont:[UIFont boldSystemFontOfSize:16]];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[nameLabel setTextColor:[UIColor whiteColor]];
[nameLabel setNumberOfLines:0];
[self.contentView addSubview:nameLabel];
switchButton = [[UISwitch alloc] initWithFrame: CGRectMake(230, 17, 100, 30)];
[switchButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[switchButton addTarget:self action:@selector(switchActivated:) forControlEvents:UIControlEventTouchUpInside];
[switchButton setHidden:YES];
[self.contentView addSubview:switchButton];
}
return self;
}
동작 방법
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell *tableViewCell = [aTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"homeReportCustomizationCell_%d",indexPath.row]];
if(!tableViewCell)
{
tableViewCell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Cell_%d",indexPath.row]];
}
...........
}
이'[switchButton setHidden : YES];를 제거하고 –
을 확인하십시오. 다른 방법으로이 단추를 숨기거나 제어 할 수 있습니다. 이제 단추를 클릭 할 수 있지만 동작 방법으로 이동하지 않습니다. –
무엇을할까요? self.contentView입니까? cell.contentView 여야합니다. 확인해 줘. –