有人可以幫助我如何使在代碼中創建的UIView位於所有其他視圖之上?其中tableView是父視圖和subSelectionView是我的自定義兄弟姐妹視圖,我想使它在tableView頂部..我有下面的代碼:在所有其他視圖上放置UIView
這是我didSelectRowAtIndexPath完整的源代碼:,從哪裏我編程方式添加的UIView實例..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Execute upon selection
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[tableView viewWithTag:199]removeFromSuperview];
// Get the cell size
CGSize cellSize = [tableView cellForRowAtIndexPath:indexPath].frame.size;
// Contact Details Container
UIView *subSelectionView;
if(indexPath.row < [contacts count] - 6)
subSelectionView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, (int)cellSize.width - 20, (int)cellSize.height + 130)];
subSelectionView.backgroundColor = [UIColor grayColor];
subSelectionView.layer.borderColor = [UIColor grayColor].CGColor;
subSelectionView.layer.borderWidth = 1;
subSelectionView.alpha = 0.9;
subSelectionView.tag = 199;
subSelectionView.layer.cornerRadius = 5.0;
// Contact Name Container
UIView *contactNameSubSelectionView;
if(indexPath.row < [contacts count] - 6)
contactNameSubSelectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, (int)cellSize.width - 20, (int)cellSize.height)];
contactNameSubSelectionView.backgroundColor = [UIColor grayColor];
contactNameSubSelectionView.alpha = 0.5;
[subSelectionView addSubview:contactNameSubSelectionView];
// Contact Name Label
Contacts *contact = [self.contacts objectAtIndex:indexPath.row];
NSString *contactName = [NSString stringWithFormat:@" %@ %@ ", contact.fname, contact.lname];
UILabel *contactNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, (int)cellSize.width, (int)cellSize.height)];
contactNameLabel.layer.cornerRadius = 4.0;
[contactNameLabel setText: contactName];
[contactNameLabel setTextColor:[UIColor blackColor]];
[contactNameLabel setFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]];
[contactNameSubSelectionView addSubview:(UIView *)contactNameLabel];
// Buttons
UIButton *buttonMobile = [[UIButton alloc]initWithFrame:CGRectMake(10, cellSize.height + 10, 30, 30)];
buttonMobile.layer.borderWidth = 1;
[buttonMobile setTitle:@"..." forState:UIControlStateNormal];
[buttonMobile addTarget:self action:@selector(btPressed:) forControlEvents:UIControlStateNormal];
[subSelectionView addSubview:(UIView *) buttonMobile];
[[tableView cellForRowAtIndexPath:indexPath]insertSubview:subSelectionView aboveSubview:self.view];
[self.parentViewController.view bringSubviewToFront:subSelectionView];
[tableView reloadData];
}
但沒有工作..
下圖顯示了我subSelectionView,按鈕是在它與subSelectionView是的tableView內。現在,當我點擊該按鈕時,問題是我實際上無法點擊它。即使存在我的代碼,它也直接關注tableView。有人可以幫我嗎?....
感謝皮特..我已經審查了它,並將按鈕啓用屬性設置爲是,但仍然無法正常工作..嗯..我正確使用此代碼:[[tableView cellForRowAtIndexPath:indexPath] insertSubview:subSelectionView aboveSubview:self.view ];? – Aldee 2012-01-31 08:16:19
如果你能看到子視圖,那麼是的 - 問題是它沒有收到事件。 – 2012-01-31 08:38:52