2
我有一個視圖由一個標籤和兩個按鈕組成,我命名爲UIView *footerView
,因爲我在我的表視圖的最後一部分中實現了這一點。UIButton不能在UItableViewCell中工作
我可以看到細胞內部的觀點:我這個觀點用[cell.contentView addSubview: footerView]
這是我的問題成爲indexPath.section = 3
的看法。但我不能點擊按鈕,因爲單元格被選中而不是按鈕(它們在單元格內)。
我該如何解決這個問題? 我的按鈕甚至不可選!
下面的代碼...在cellForRowAtIndexPath:
if (section == 3){
cell = nil;
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (indexPath.row ==0){
cell.contentMode = UIViewContentModeScaleToFill;
[cell.contentView addSubview:self.footerView];
}
}
而頁腳視圖(萬一有人需要看到這一點):
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 3, 300, 44)];
textView.text = @"Terms and Conditions: Lorem ipsum dolor sit amet, con- sectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut";
textView.backgroundColor = [UIColor clearColor];
textView.font = [UIFont systemFontOfSize:10];
[self.footerView addSubview:textView];
//create the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0, 60, 300, 44)];
//set title, font size and font color
[button setTitle:@"Create Account" forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
// [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//set action of the button
[button addTarget:self action:@selector(createAccount:)
forControlEvents:UIControlEventTouchUpInside];
[button setEnabled:YES];
//add the button to the view
[self.footerView addSubview:button];
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancelButton setFrame:CGRectMake(0, 107, 300, 44)];
//set title, font size and font color
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
// [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//set action of the button
[cancelButton addTarget:self action:@selector(cancelPressed:)
forControlEvents:UIControlEventTouchUpInside];
[cancelButton setEnabled:YES];
//add the button to the view
[self.footerView addSubview:cancelButton];
TRIED >>>不工作! – Legolas
+1第二位應該解決問題。 –
@paul:我已經照顧到身高問題了。它比我的那個部分的子視圖更大。問題仍未解決。 – Legolas