0

横向きビューでは、UITableViews を動的に追加する UIScrollView があります。UITableView の幅は 200px であるため、画面上に 2 ~ 3 個表示できます。各セルにはボタンがあります。

ボタンが押されたときに、そのボタンがどの UITableView に属しているかを知るにはどうすればよいですか?

cellForRowAtIndexPath の PS 実装:

cell = (CellHistory*)[tableView dequeueReusableCellWithIdentifier:@"Cell"];

if(!cell)
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CellHistory" owner:nil options:nil];
    for(id currentObject in topLevelObjects)
    {
        if([currentObject isKindOfClass:[CellHistory class]])
        {
            cell = (CellHistory *)currentObject;
            break;
        }
    }
}


UIButton *noteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[noteButton setFrame:CGRectMake(0, 0, 44, 44)];
[cell addSubview:noteButton];
[noteButton addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];

return cell;

PS2 UITableViews を UIScrollView に追加する方法:

for (int i=0; i<allDays.count; i++) {
            CGRect landTableRect = CGRectMake(landContentOffset+0.0f, 60.0f, 200.0f, 307.0f);
            landTableView = [[UITableView alloc] initWithFrame:landTableRect style:UITableViewStylePlain];
            [landTableView setTag:i];
            [landTableView setNeedsDisplay];
            [landTableView setNeedsLayout];
            landTableView.delegate = self;
            landTableView.dataSource = self;
            [_landScrollView addSubview:landTableView];
            [landTableView reloadData];
            landContentOffset += landTableView.frame.size.width;
            _landScrollView.contentSize = CGSizeMake(landContentOffset, _landScrollView.frame.size.height);
            [allLandTableViews addObject:landTableView];
        }
4

3 に答える 3