We are developing with objective-c.
Allocate the UITableViewCell class to the screen of the UITableView class and I'm trying to allocate an image of the UIView class in the process inside the UITableViewCell class and process the touch event for it. touchesEnded is not called. Below is part of the code.
// UITableView:PhotoListViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.tableView == nil) {
self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tableView.backgroundColor = BODY_COLOR;
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
}
[self.tableView.layer setBorderColor:LOG_COLOR.CGColor];
[self.tableView.layer setBorderWidth:4.0f];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
//savebutton
CGRect frame = saveBarController_.view.frame;
frame.origin.y = self.tableView.frame.size.height;
saveBarController_.view.frame = frame;
[self.view addSubview:saveBarController_.view];
PRINT_RECT(saveBarController_.view.frame);
[self.tableView reloadData];
PBDataManager *manager = [[[PBDataManager alloc]init] autorelease];
[manager save:nil];
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
ThumbnailCell *cell = (ThumbnailCell *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ThumbnailCell alloc]init]autorelease];
}
[cell setThumbnail:[thumbnailManager_ thumbnailAtRow:indexPath.row]];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
// UITableViewCell:ThumbnailCell.m
- (id)init
{
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
thumbnailViews_ = [[NSArray arrayWithObjects:
[[[ThumbnailView alloc]init]autorelease]
,[[[ThumbnailView alloc]init]autorelease]
,[[[ThumbnailView alloc]init]autorelease]
,[[[ThumbnailView alloc]init]autorelease]
,nil]retain];
int count = 1;
int margin = 4;
int width = 75;
for (ThumbnailView *thumb in thumbnailViews_) {
thumb.frame = CGRectMake(count * margin + (count-1) * width, 4, 75, 75);
thumb.autoresizingMask = 0;
thumb.userInteractionEnabled = YES;
[self addSubview:thumb];
count++;
}
}
return self;
}
// UIView:ThumbnailView.m
- (id)init
{
self = [super initWithFrame:CGRectMake(0, 0, 75, 75)];
if (self) {
[self setupLayer];
}
return self;
}
- (void)setupLayer
{
imageLayer_ = [[UIImageView alloc]initWithFrame:self.bounds];
imageLayer_.frame = self.bounds;
videoLayer_ = [[UIImageView alloc]initWithFrame:self.bounds];
videoLayer_.frame = self.bounds;
duration_ = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 15)];
duration_.backgroundColor = [UIColor clearColor];
duration_.frame = CGRectMake(30, 60, 40, 15);
[self addSubview:imageLayer_];
[self addSubview:videoLayer_];
[self addSubview:duration_];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// Touch event is not notified
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// Touch event is not notified
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// Touch event is not notified
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// Touch event is not notified
}
This is the code of an old project around 2016, and the touch event is not notified when running on the current OS. iPhone5: iOS10.3.4 In contrast to the above code, you will receive a touch event notification on your device. iPad (7th generation): iOS 15.1 You will not receive touch event notifications on your device. I don't know the cause, so what should I do?
The development environment is Xcode12.5 Will be.
I look forward to working with you.