【问题标题】:UIButton in UITableView header not working?UITableView 标头中的 UIButton 不起作用?
【发布时间】:2011-06-30 15:24:08
【问题描述】:

我在 UITableView 标头中添加了一个 UIBUtton,但它似乎不起作用。它是可点击的,但是当附加一个 IBAction 到它时,它会失败并且什么都不做。

我已经在线阅读并看到将其放入您的文件所有者中,但我不能这样做。当我将操作放入时,它只会显示在我的 First Responder 中。

我也尝试将它放在另一个文件中,但是这样做时不会让我将它拖到另一个文件中。

文件:

RootViewController.h 根视图控制器.m TableViewAppDelegate.h TableViewAppDelegate.m DetailViewController.h DetailViewController.m

RootViewController.h

@interface RootViewController : UITableViewController {
    NSMutableArray *listOfItems;
    Sqlite *database;
    NSTimer *myTimer;
    UITextView *myTextField;
}

- (IBAction)addAlbum;

RootViewController.m

#import "RootViewController.h"
#import "TableViewAppDelegate.h"
#import "DetailViewController.h"

@implementation RootViewController

// If a user adds a photo album
- (IBAction)addAlbum {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add Gallery" message:@"this gets covered" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Ok", nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, -80);
[alert setTransform:myTransform];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
[alert setTag:1];
}

感谢任何帮助! 谢谢。

【问题讨论】:

  • 可能缺陷在您的代码中。发布一些,我们可以确定。
  • 刚刚发布了一些...请询问您是否需要查看其他内容!谢谢。

标签: xcode uitableview uibutton ibaction


【解决方案1】:

如果您从 .xib 加载表头视图,请将 .xib 的“文件所有者”设为您的 ViewController 子类,以呈现 UITableView,并将按钮中的所需事件连接到文件所有者中所需的 IBAction。如果您在 tableView:viewForHeaderInSection: 方法中以编程方式创建按钮,则必须在按钮对象上使用此方法自行连接按钮上的操作:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

编辑:您应该发布您的 tableView:viewForHeaderInSection: 代码,以便我们提供更具体的建议。

【讨论】:

  • 那么你在哪里创建重视图?
猜你喜欢
  • 1970-01-01
  • 2021-04-22
  • 2016-10-20
  • 1970-01-01
  • 1970-01-01
  • 2020-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多