我有一个带有UINavigationController的应用程序,其中包含一堆UITableViewControllers,我根据用户选择的内容将其换出。所有的UITableViewControllers都有一个按钮" Add Event"。在大约一半的表视图控制器上,该按钮根本不会触发。对于我的生活,我无法弄清楚原因。
这是一个无法工作的初始函数的示例。有问题的按钮是" doneButton"。单击时不会触发addEvent()。
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle: UITableViewStyleGrouped];
if (self) {
// initialize toolbar
toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake( 0, 0, 768, 44 )];
titleLabel = [[UILabel alloc] initWithFrame: CGRectMake( 284, 4, 200, 35 )];
titleLabel.text = @"End Repeat";
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont boldSystemFontOfSize: 20];
titleLabel.textColor = [UIColor grayColor];
titleLabel.backgroundColor = [UIColor clearColor];
[toolbar addSubview: titleLabel];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle: @"Add Event" style: UIBarButtonItemStyleDone target: self action: @selector(addEvent)];
NSArray *buttonArray = [NSArray arrayWithObjects: flexibleSpace, doneButton, nil];
[toolbar setItems: buttonArray];
[self.view addSubview: toolbar];
// initialize date picker
datePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake( 0.0, 0.0, 768.0, 216.0 )];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget: self action: @selector(changeDate) forControlEvents: UIControlEventValueChanged];
[self roundDatePicker];
[self parseDone];
}
return self;
}
这是一个可以工作的初始函数的例子:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle: UITableViewStyleGrouped];
if (self) {
// Custom initialization
caController = [[CAViewController alloc] init];
selectedRow = 0;
self.title = @"Calendar";
self.toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake( 0, 0, 768, 44 )];
titleLabel = [[UILabel alloc] initWithFrame: CGRectMake( 284, 4, 200, 35 )];
titleLabel.text = @"Select Calendar";
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont boldSystemFontOfSize: 20];
titleLabel.textColor = [UIColor grayColor];
titleLabel.backgroundColor = [UIColor clearColor];
[toolbar addSubview: titleLabel];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle: @"Add Event" style: UIBarButtonItemStyleDone target: self action: @selector(addEvent)];
NSArray *buttonArray = [NSArray arrayWithObjects: flexibleSpace, doneButton, nil];
[toolbar setItems: buttonArray];
[self.view addSubview: toolbar];
}
return self;
}
答案 0 :(得分:1)
逐步重建我的应用程序2个月,我终于找到了它!这阻止了我的按钮:
- (UIView*) tableView: (UITableView*) tableView viewForHeaderInSection: (NSInteger) section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 1)];
}
对于我的生活,我无法弄清楚这些代码的作用或者为什么我首先将它放在那里。我删除了它,现在一切似乎都正常。