我現在有在該按鈕時每個部分的viewForFooterInSection
一個按鈕,從0至65的高度的高度增加的行5-10的高度,如下所示:如何在UITableView的每個部分有不同的行高?
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor whiteColor];
self.moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.moreButton.frame = CGRectMake(0, 0, 320, 44);
[self.moreButton setImage:[UIImage imageNamed:@"downarrow.png"] forState:UIControlStateNormal];
[self.moreButton addTarget:self action:@selector(moreButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:self.moreButton];
return view;
}
- (void)moreButtonSelected:(id)sender {
if (_hasPressedShowMoreButton == NO){
self.hasPressedShowMoreButton = YES;
}
else if (_hasPressedShowMoreButton == YES){
self.hasPressedShowMoreButton = NO;
}
[self.matchCenter reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_hasPressedShowMoreButton == YES){
return 65;
}
else if (_hasPressedShowMoreButton == NO){
if (indexPath.row > 3){
return 0;
}
else{
return 65;
}
}
}
這就意味着是「顯示更多」類型的動作,這樣當按下時,其餘行將出現,而不是僅前4個。問題是,當按下某個節的頁腳中的按鈕時,它會展開所有部分到10行,而不僅僅是按下按鈕的那一行。我怎樣才能指定按鈕被按下的部分?
編輯:
我試過以下的建議,並做如下圖所示,但它引發的崩潰與錯誤'NSInvalidArgumentException', reason: '-[UIButton section]: unrecognized selector sent to instance 0x7f94840640b0'
。
代碼:
- (void)moreButtonSelected:(NSIndexPath *)indexPath{
if (_hasPressedShowMoreButton == NO){
self.hasPressedShowMoreButton = YES;
indexPath.section == _expandedSection;
}
else if (_hasPressedShowMoreButton == YES){
self.hasPressedShowMoreButton = NO;
}
[self.matchCenter reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_hasPressedShowMoreButton == YES){
if (indexPath.section == _expandedSection){
return 65;
}
}
else if (_hasPressedShowMoreButton == NO){
if (indexPath.row > 3){
return 0;
}
else{
return 65;
}
}
}
您不能使用單個法爾'_hasPressedShowMoreButton'。您需要跟蹤所有部分的按鈕狀態。 – rmaddy 2014-10-07 17:30:59
@rmaddy啊,有道理。介紹如何跟蹤每個按鈕的狀態? – Ghobs 2014-10-07 17:33:34