在UIViewController之上显示自定义UIView

时间:2010-11-25 00:49:59

标签: iphone uiview uiviewcontroller modalviewcontroller

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

目标是除了iPhone之外它的行为类似于ModalViewController。有没有人对如何实现这种行为或者是否有更好的实现有任何建议?

3 个答案:

答案 0 :(得分: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。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

使用一些动画来实现此效果。当UIView出现时,它会像某些键盘行为一样抬起UITableView。因此,您必须在self.view上添加SubView并修改UITableView的框架。并且,UITableView应该是self.view的子视图,如果self.view与UITableView相同,那么你没有自我视图来添加这个UIView。

相关问题