【问题标题】:UIViewController Problem with IBIB 的 UIViewController 问题
【发布时间】:2011-06-22 20:02:26
【问题描述】:

这就是我的工作

  1. 使用 UIViewController 子类设置视图
  2. 转到 IB,然后将视图拉入 iphone
  3. 在 UIView 上拉一个导航栏
  4. 在下面的空白处拉一个tableview。

当我运行界面生成器时,一切正常。

但是这些东西不起作用。

  1. 如果我在导航栏顶部添加一个按钮,该按钮会出现,但不会调用 IBAction。该按钮似乎位于导航栏下方(其他地方)

  2. 如果我为 tableView 添加页脚视图,它不会出现。我相信 UIView 再次掩盖了它或其他东西......

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section                
    
    {
    
    UIView *viewForFooter = [[UIView alloc] init ];
    UIButton *footerButton = [[UIButton alloc] initWithFrame:CGRectMake(200, 40, 100, 40)];
    footerButton.titleLabel.text = @"Forgot Login";
    //self.forgotLogin = footerButton;
    [viewForFooter addSubview:footerButton];    
     return viewForFooter;
    
    
    }
    

为什么?

【问题讨论】:

  • 您必须使用 IB 将按钮链接到选择器。你做到了吗?
  • 你在设置表格视图的委托和数据源吗?另外,您是否设置了UINavigationController
  • 请编辑您之前的帖子UIBarButtonItem not reacting to click,而不是针对同样的问题发布新帖子。
  • 一切正常。 !
  • 为什么不直接做一个 UITableViewController?

标签: iphone objective-c cocoa-touch uiviewcontroller interface-builder


【解决方案1】:

1) 点击无反应:尝试在代码中添加动作。如果它有效,则连接 IBAction 有问题。

[self.barButton setTarget:self];
[self.barButton setAction:@selector(IBActionHandler:)];

作为备用,你也可以尝试在代码中添加按钮:

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                         target:self
                       selector:@selector(IBActionHandler:)];
self.navigationItem.rightBarButtonItem = barButton;
[barButton release];

2) 不可见按钮 - 我认为您的按钮是自定义 UIButton,因此它是透明的。标题不可见,因为您必须像这样设置它:

[footerButton setTitle:@"Forgot Login" forState:UIControlStateNormal];

如果您想要一个常规的圆角按钮,您必须在 创建它之后设置框架。

UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
// Careful, this button is autoreleased.
[footerButton setFrame:CGRectMake(200, 40, 100, 40)];

顺便说一句,您的 CGRects 也可能有问题。 footerView 可能也应该使用框架正确初始化,您可能必须实现

 -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

也是。

PS:使用标准的 UITableViewController 实际上可能是个好主意。 快乐编码!

【讨论】:

    猜你喜欢
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 2019-06-16
    • 2011-04-10
    • 2011-10-23
    相关资源
    最近更新 更多