0

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

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

4

3 回答 3

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 的东西。

于 2010-11-25T08:07:08.313 回答
0

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

于 2010-11-25T00:59:09.863 回答
0

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

于 2010-11-25T07:52:34.480 回答