我正在创建一个自定义下拉菜单。在按钮上单击我取消隐藏UIView,它是我的根视图的子视图。在那个子视图中我已经以编程方式添加了UItableview。到目前为止我的代码工作正常,但我在使用我的数据数组填充表时卡住了。所以任何人都可以帮我解决这个问题.....提前感谢
我也分配了UItableView委托和数据源..
这是我的实施
- (void)viewDidLoad
{
[super viewDidLoad];
self.grades = [[NSArray alloc]initWithObjects:@"Excellent",@"Good",@"ok",@"Not Good", nil];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.coverView = [[UIView alloc]init];
self.shadowView = [[UIView alloc]init];
self.coverView = [[UIView alloc] initWithFrame:CGRectMake(90.0f, 220.0f, 150.0f, 200.0f)];
self.coverView.backgroundColor = [UIColor whiteColor];
CALayer * layer = self.coverView.layer;
layer.shadowOffset = CGSizeMake(1, 1);
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowRadius = 4.0f;
layer.shadowOpacity = 0.80f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
[[self view] addSubview:self.coverView];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 140.0f, 200.0f)];
[self.coverView addSubview:self.tableView];
self.coverView.hidden = YES;
[self.tableView reloadData];
}
- (IBAction)buttonClicked:(id)sender
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.shadowView = [[UIView alloc] initWithFrame:screenRect];
self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
[self.view addSubview:self.shadowView];
[[self view] addSubview:self.coverView];
self.coverView.hidden = NO;
[self fadeIn];
[self.tableView reloadData];
}
- (IBAction)screenTapped:(id)sender
{
NSLog(@"Screen Tapped");
[self fadeOut];
self.shadowView.hidden = YES;
[self.shadowView removeFromSuperview];
}
- (void)fadeIn
{
self.coverView.transform = CGAffineTransformMakeScale(0.5, 0.5);
self.coverView.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
self.coverView.alpha = 1;
self.coverView.transform = CGAffineTransformMakeScale(1.4,1.4);
}];
}
- (void)fadeOut
{
[UIView animateWithDuration:.35 animations:^{
self.coverView.transform = CGAffineTransformMakeScale(1.3, 1.3);
self.coverView.alpha = 0.0;
} completion:^(BOOL finished){
if (finished)
{
[self.coverView removeFromSuperview];
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.grades count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentifier = @"Cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.grades objectAtIndex:indexPath.row];
return cell;
}
答案 0 :(得分:0)
看起来你需要在[UITableView alloc]之后设置委托。
self.tableView = [[UITableView alloc] ....
self.tableView.delegate = self;
self.tableView.dataSource = self;