Iphone UIViewController与IB之间的问题

Iphone UIViewController与IB之间的问题,iphone,objective-c,cocoa-touch,uiviewcontroller,interface-builder,Iphone,Objective C,Cocoa Touch,Uiviewcontroller,Interface Builder,我就是这么做的 使用UIViewController子类设置视图 转到IB,将视图拉入iphone 将导航栏拉到UIView上 在下面的空间中拖动一个tableview 当我运行interface builder时,一切看起来都很好 但这些东西都不起作用 如果我在导航栏顶部添加一个按钮,则会显示该按钮,但不会调用iAction。该按钮似乎位于导航栏下方(其他位置) 如果为tableView添加页脚视图,则不会显示该视图。我相信UIView再次掩盖了它或其他东西 - (UIView *)table

我就是这么做的

  • 使用UIViewController子类设置视图
  • 转到IB,将视图拉入iphone
  • 将导航栏拉到UIView上
  • 在下面的空间中拖动一个tableview
  • 当我运行interface builder时,一切看起来都很好

    但这些东西都不起作用

  • 如果我在导航栏顶部添加一个按钮,则会显示该按钮,但不会调用iAction。该按钮似乎位于导航栏下方(其他位置)

  • 如果为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;
    
    
    }
    
  • 为什么?

    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)];
    
    顺便说一句,你的CGRECT也可能有问题。footerView可能还应该用一个框架正确初始化,您可能需要实现

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

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

    您必须使用IB将按钮链接到选择器。您已经这样做了吗?您正在设置表视图的委托和数据源吗?另外,您是否有
    UINavigationController
    设置?请编辑您以前的帖子,而不是针对同一问题发布新帖子。一切都已正确完成!为什么不制作一个UITableViewController呢?