2014-10-09 61 views
0

我正在創建一個自定義的下拉菜單。在按鈕上點擊我取消隱藏UIView,它是我的根視圖的子視圖。在子視圖中,我已經以編程方式添加了UItableview.Till這個我的代碼工作正常,但我卡住時,與我的數據array.so任何人都可以幫助我解決這個問題.....我提前致謝以編程方式填充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

Missing實現-heightForRowAtIndexpath UITableview數據源方法.. – ibiren 2014-10-09 14:35:38

回答

0

看起來像你需要[UITableView的頁頭]後設置的代表。

self.tableView = [[UITableView alloc] .... 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 
相關問題