TTTableViewController showMenu:forCell: 示例

发布于 2024-10-10 21:56:59 字数 201 浏览 7 评论 0原文

我正在寻找一个示例,说明如何创建动画行菜单,例如 Facebook 和 Facebook 等。 iPhone 版 Twitter 应用程序有。我看到 TTTableViewControllershowMenu:forCell: 方法,但我还没有找到任何如何使用它的示例。特别是在 URL 导航器选择器的上下文中,但任何示例都很棒。

I'm looking for an example of how to create an animated row menu like the Facebook & twitter apps for iphone have. I see the TTTableViewController has the showMenu:forCell: method, but I have not been able to find any examples of how to use it. Specifically in the context of a URL Navigator selector, but any example would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只涨不跌 2024-10-17 21:56:59

你能找到这方面的例子吗?

我也遇到了和你一样的问题。一周前我找不到使用 TTTableViewController showMenu:forCell: 方法的示例。弄乱代码后,我想出了这个...

创建 TTTableViewCell 的子类并向视图添加 UIButton (作为启动菜单视图的触发器)。

@interface MyViewCell : TTTableViewCell {
}

- (id) initWithName:(NSString *)name target:(id)target action:(SEL)action {
  // ...

    UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    moreButton.frame = CGRectMake(268.0f, 6.0f, 32.0f, 32.0f);
    [moreButton setImage:TTIMAGE(@"bundle://Icon_More.png")
                     forState:UIControlStateNormal];
    [moreButton addTarget:target action:action 
         forControlEvents:UIControlEventTouchUpInside];
    [self moreButton];

  // ...
}

接下来,创建 TTTableViewController 的子类并将自定义 TTTableViewCell 添加到数据源。

@interface MyTableViewController : TTTableViewController {
}

- (void) createModel {  
  self.dataSource = [TTListDataSource dataSourceWithObjects:
    [[[ContactViewCell alloc] initWithName:@"Cell 1"
                                    target:self 
                                    action:@selector(moreButtonDidPress:)]
                                    autorelease],
    [[[ContactViewCell alloc] initWithName:@"Cell 2"
                                    target:self 
                                    action:@selector(moreButtonDidPress:)]
                                    autorelease],
    nil];
}

在操作处理程序中,这就是调用 showMenu:forCell: 的地方。诀窍是确定按钮属于哪个单元格,然后用菜单视图替换该单元格。这就是我所做的。

- (void) moreButtonDidPress:(id)sender {
  // Load our custom menu view from a nib.
  UIView *menuView = [[UIView alloc] initWithFrame:cell.contentView];

  UIButton *moreButton = (UIButton *) sender;
  // Convert plusButton bounds to the the coordinate system of table view
  // and then get the cell containing the button.
  CGRect coord = [plusButton convertRect:moreButton.bounds toView:self.tableView];
  NSIndexPath *path = [self.tableView indexPathForRowAtPoint:coord.origin];
  TTTableViewCell* cell = (TTTableViewCell*) [self.tableView 
                                              cellForRowAtIndexPath:path]; 

  // Now call showMenu with the menu to display on the associated cell.
  [self showMenu:menuView forCell:cell animated:YES]; 
}

它并不完全使用 URL 导航器选择器,但它很实用。

Were you able to find an example on this.

I, too, was stuck with the same problem as you did. I couldn't find an example of using TTTableViewController showMenu:forCell: method a week ago. After messing with the code, I came up with this...

Create a subclass of TTTableViewCell and add a UIButton (as a trigger to launch the menu view) to the view.

@interface MyViewCell : TTTableViewCell {
}

- (id) initWithName:(NSString *)name target:(id)target action:(SEL)action {
  // ...

    UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    moreButton.frame = CGRectMake(268.0f, 6.0f, 32.0f, 32.0f);
    [moreButton setImage:TTIMAGE(@"bundle://Icon_More.png")
                     forState:UIControlStateNormal];
    [moreButton addTarget:target action:action 
         forControlEvents:UIControlEventTouchUpInside];
    [self moreButton];

  // ...
}

Next, create a subclass of TTTableViewController and add custom TTTableViewCells to the data source.

@interface MyTableViewController : TTTableViewController {
}

- (void) createModel {  
  self.dataSource = [TTListDataSource dataSourceWithObjects:
    [[[ContactViewCell alloc] initWithName:@"Cell 1"
                                    target:self 
                                    action:@selector(moreButtonDidPress:)]
                                    autorelease],
    [[[ContactViewCell alloc] initWithName:@"Cell 2"
                                    target:self 
                                    action:@selector(moreButtonDidPress:)]
                                    autorelease],
    nil];
}

In the action handler, that's where showMenu:forCell: is called. The trick is to determine which cell the button belongs to and consequently replace that cell with the menu view. This is what I did.

- (void) moreButtonDidPress:(id)sender {
  // Load our custom menu view from a nib.
  UIView *menuView = [[UIView alloc] initWithFrame:cell.contentView];

  UIButton *moreButton = (UIButton *) sender;
  // Convert plusButton bounds to the the coordinate system of table view
  // and then get the cell containing the button.
  CGRect coord = [plusButton convertRect:moreButton.bounds toView:self.tableView];
  NSIndexPath *path = [self.tableView indexPathForRowAtPoint:coord.origin];
  TTTableViewCell* cell = (TTTableViewCell*) [self.tableView 
                                              cellForRowAtIndexPath:path]; 

  // Now call showMenu with the menu to display on the associated cell.
  [self showMenu:menuView forCell:cell animated:YES]; 
}

It's not exactly using a URL Navigator selector, but it's functional.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文