いくつかのサブビューを含むビューがあり、これらの各サブビューには透明なボタンがあります。これらのビューを for ループのメイン UIView に配置します。このループでは、サブビュー ボタン プロパティのターゲットとアクションも割り当てます。私の問題は、ループで作成された最初のビューとボタンのみが機能することです(つまり、クリックするとアクションが呼び出されます)。
ループの関連部分は次のようになります。
// _categories is an array
for (int i = 0; i < _categories.count; i++) {
[...]
Category *category = [_categories objectAtIndex:i];
CategoryView *categoryView = [[CategoryView alloc] initWithFrame:categoryRect andTitle:category.name];
[...]
categoryView.categoryButton.tag = [category.categoryId intValue];
[categoryView.categoryButton addTarget:self action:@selector(openCategoryWithId:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:categoryView];
[...]
}
アクションは次のようになります。
- (void)openCategoryWithId:(UIButton *)sender
{
// Only gets called when I click on the first views button.
NSLog(@"Hello");
}
サブビューの強力なプロパティを作成しようとしましたが、役に立ちませんでした。
私が何をすべきかについてのアイデアはありますか?