我想創建一個部分標題加載一個筆尖文件並將其設置爲標題UIView。這個nib文件還會有一個關聯的類,其中的出口和動作是連接的,所以我想像正常一樣用nib加載那個類。使用筆尖作爲表部分標題與筆尖類
我搜遍了網頁,發現了幾個類似的答案,但我無法爲我工作。在玩了幾天之後,我設法讓視圖正確顯示,但是儘管添加了連接並告訴文本以不同的方式顯示,但它並沒有做任何事情。
例如,它應該清除節標題文本,如果它是init的nil,它會這樣做,但它仍然顯示相同的文本,嘗試更改它並不反映任何與按鈕的連接都不會觸發。
這裏是我的觀點
@interface ADUNewRowHeaderViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *sectionTitleField;
@property (strong, nonatomic) IBOutlet UIButton *addRowBtn;
@property(strong,nonatomic) NSString* sectionTitle;
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
title:(NSString*) titleOrNil;
@end
視圖控制器,這裏是它的上市爲
@property(nonatomic, strong) ADUNewRowHeaderViewController* secHeader;
,並在實際的表視圖控制器的實現
@implementation ADUNewRowHeaderViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil title:(NSString *)titleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
if(titleOrNil != nil)
{
[self setSectionTitle:titleOrNil];
}
else
{
[self setSectionTitle:@""];
}
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)setSectionTitle:(NSString *)sectionTitle
{
_sectionTitle = sectionTitle;
[[self sectionTitleField] setText:sectionTitle];
}
@end
viewDidLoad下的實現文件爲
[self setSecHeader:[[ADUNewRowHeaderViewController alloc] initWithNibName:nil bundle:nil title:nil]];
[[[self secHeader] addRowBtn] addTarget:self action:@selector(addNewRow:) forControlEvents:UIControlEventTouchUpInside];
和
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [[self secHeader] view];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return [[self secHeader] view].bounds.size.height;
}
這對於行動
- (IBAction)addNewRow:(id)sender;
除了我必須刪除'CGRect frame = self.frame; self.view.frame = CGRectMake(0,0,frame.size.width,frame.size.height);'從setUp和它的工作後 – 2013-04-27 21:48:43
也UIButton我有在筆尖反應明顯慢於它的工具欄最初是在,像我可以在幾秒鐘內按下工具欄按鈕,它會immikidiately添加這些行,但如果我在一秒鐘內按下新的筆尖按鈕多次,它可能只能添加一個或兩個。該按鈕正常響應,它只是行不會立即添加(這不是一個問題,只是我注意到) – 2013-04-27 21:52:03
請選擇此爲答案。 – 2013-04-27 22:04:03