【发布时间】:2014-10-09 14:26:22
【问题描述】:
我正在创建一个自定义下拉菜单。单击按钮时,我将取消隐藏 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;
}
【问题讨论】:
-
缺少 -heightForRowAtIndexpath UITableview 数据源方法的实现..
标签: ios objective-c iphone uitableview