2010-11-25 71 views
0

我正在寻找关于实现以下功能的最佳方式的意见。我有一个UIViewController与分组格式的UITableView。每个TableViewCell都包含一个NSString。当用户点击一个单元格时,我想在我的didSelectRowForIndexPath方法中弹出一个带有单个文本字段的UIView,该字段在选定的给定单元格中用NSString预填充。显示UIVIew的原因是我希望它是大约280 x 380帧,仍然可以看到一些UITableView。在UIViewController上显示自定义UIView

目标是它的行为像一个ModalViewController除了iPhone。有没有人有任何建议如何实施这种行为,或者如果有更好的实施?

回答

1

创建了UIView(带内的的UITextField)预先,并使其隐藏的:

// Of course, these instance variable names are made up, and should be changed 
self.myModalView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 380)] autorelease]; 
[self.view addSubview:self.myModalView] 

self.myTextField = [[[UITextField alloc] init] autorelease]; 
[self.myModalView addSubview:self.myTextField]; 

self.myModalView.hidden = YES; 

然后,当用户选择一排,填充文本字段,并显示模态视图:

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath { 
    // Replace stringAtIndexPath with however your data source accesses the string 
    NSString* myString = [self stringAtIndexPath:indexPath]; 
    self.myTextField.text = myString; 
    self.myModalView.hidden = NO; 
} 

如果你想要看起来,你可以在显示模态视图之前做一些CATransition的东西。

+0

谢谢你,这是实现它的好方法。 – aahrens 2010-11-27 03:20:08

0

我想你可以在UITableView中使用“addSubView”。直接将ModalView添加到您的UITableView。它会工作。

0

使用一些动画来实现这种效果。当UIView出现时,它将解除UITableView,就像某些键盘行为一样。所以,你必须在self.view上添加SubView并修改UITableView的框架。而且,UITableView应该是self.view的子视图,如果self.view与UITableView相同,那么你没有self.view来添加这个UIView。

相关问题