私のアプリでは、ナビゲーション バーに 1 つのボタン ( browsebutton など) があり、ボタンをクリックすると、CGRectMake 関数を使用して動的に取得した1 つのビュー ( browseView など) が表示されます。
BrowseViewに UITableView ( browseTableView など) を追加しました。
テーブルは BrowseView に追加されますが、デリゲート メソッドが機能しません。
適切な方向を教えてください。
私のコードは次のとおりです。
MainViewController.h
@interface MainViewController : UIMainViewController <UITableViewDelegate,UITableViewDataSource>
MainViewController.m
browseTableView.delegate = self;
browseTableView.dataSource =self;
-(void)BrowseButton {
browseView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 300.0, 500.0)];
browseView.backgroundColor = [UIColor whiteColor];
browseView.opaque = NO;
[browseView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[browseView.layer setBorderWidth: 4.0];
[browseView setBackgroundColor:[UIColor clearColor]];
browseTableView = [[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 300, 460)];
[browseView addSubview:browseTableView];
[self.view addSubview:browseView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
categoryArray = [[NSMutableArrayalloc]initWithObjects:@"Platinum",@"Diamond",
@"Gold",@"Silver", nil];
return [categoryArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc]init];
cell.textLabel.text = [categoryArray objectAtIndex:indexPath.row];
return cell;
}