2011-07-25 26 views
0

我想實現一些代碼,它改變了tableView的一個部分中的頁腳文本(在viewDidAppearviewWillAppear方法中)。但我該怎麼做呢?如何手動設置TableView的一個部分的頁腳(iOS)?

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 

不符合我的要求(這僅更改一次,的tableView的加載過程中,但我需要改變頁腳文本的tableView格文本更改後。

回答

3
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ 


     return 120; 

    } 



    -(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
     if (section == 0) { 
      return @"Things We'll Learn"; 
     } else { 
      return @"Things Already Covered"; 
     } 
    } 



- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    [tableView reloadData]; 
} 
+0

謝謝。它只在我使用靜態字符串的情況下才起作用。如果我在if子句中使用這樣的代碼:NSString * str = [NSString stringWithFormat:@「There are%d symbols」,[[[tableView cellForRowAtIndexPath:tappedRow] textLabel] text] length]]; return str; – LIAL

+0

我得到了應用程序的崩潰 – LIAL

+0

返回[NSString stringWithFormat:@「%@」,[firstsectionarray objectAtIndex:indexPath.row]]像這樣做所有部分,並注意numberofrowsinsection函數 –

1
  1. 實施viewForFooterInSection並添加textField那裏。同時使該文本框的屬性。

  2. 當編輯完你tableViewCells,實現textFieldDidEndEditing方法並將必要的值分配給footerView的textField。

  3. 一旦你的textField被設置,使用[tableView reloadData]再次實現viewForFooterInSection它現在應該工作。

編輯:

如果你想改變頁腳部分的標題編輯的UITableViewCell後,

  1. 設置一個全局變量或使用NSUserDefaults,表明tableViewCell有已編輯。

  2. self.tableView reloadData編輯後。

  3. 在方法titleForFooterInSection檢查該變量(這將意味着tableView已被編輯)並相應地設置標題。

+0

viewFoFooterInSection或者titleForFooterInSection ??我應該添加作爲Footer子視圖的textField按照您的建議? – LIAL

+0

是否要更改頁腳標題或是否要更改footerView內的textField? – Legolas

+0

當TableView的單元格文本發生變化時,我想在此單元的頁腳中顯示符號的數量 – LIAL

0
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    if(section == 1) 
    { 
     // For Lable 
     UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)] autorelease]; 
     tableView.sectionHeaderHeight = view.frame.size.height; 
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, view.frame.size.width - 20, 44)]; 
     label.text = [self tableView:tableView titleForHeaderInSection:section]; 
     label.font = [UIFont boldSystemFontOfSize:16.0]; 
     label.shadowOffset = CGSizeMake(0, 1); 
     label.backgroundColor = [UIColor clearColor]; 
     label.textColor = [UIColor whiteColor]; 
     label.adjustsFontSizeToFitWidth = YES; 
     [label setLineBreakMode:NSLineBreakByTruncatingTail]; 
     [label setNumberOfLines:0]; 
     label.text = @「Your Text Here…..your Text Here」; 

     [view addSubview:label]; 
     [label release]; 
     return view; 
    } 

    return nil; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    if(section == 1) 
    { 

     return 60.0; 
    } 

    return 0; 
} 
+0

還剩4年,你真的認爲現在是真的嗎? – LIAL

+2

我相信它會對某人有幫助..... :-) – Sabareesh

相關問題