2013-01-11 56 views
1

first image with home button problem second image with bar的UITableView和細胞在錯誤的地方展示內容

我有兩個問題,我的tableview,即從tablefooterview的「回家」按鈕被顯示出來(在屏幕的中間)時,尚未達到桌面視圖的結尾。正如您在第一張圖片中看到的,主屏幕按鈕出現在屏幕中間,我不想要的。它必須留在桌子的底部。

我的第二個問題是分段控制,它通常位於視圖的頂部,正在我的一個單元中重新分配,它不屬於它。我已確定細胞reusidentifier已禁用。

單元格剛剛填滿文字,所以我不明白爲什麼分段控件顯示出來。

編輯:代碼添加

代碼填充細胞:(只是一小部分,但它在另一個單元格只是其他文字,沒有什麼變化)

if(indexPath.section == 2){ 
    [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
    [[cell textLabel] setText:_actor.actorBeschrijving]; 

    if([[cell textLabel] text] == nil) 
    { 
     [[cell textLabel] setText:@"Druk om een beschrijving toe te voegen"]; 
     [[cell textLabel] setTextColor:[UIColor grayColor]]; 

    } 
} 


if(indexPath.section == 3 && control.selectedSegmentIndex == 1){ 
    if([has count] == 0){ 

     [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
     [[cell textLabel] setText: @"Voeg een nieuw object toe"]; 
    } 
    else{ 

     if(indexPath.row < [has count]){ 


      AnObject *object = (AnObject*)[has objectAtIndex:indexPath.row]; 
      [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
      [[cell textLabel] setText:object.objectNaam]; 

     } 

     if(indexPath.row == [has count]){ 
      [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
      [[cell textLabel] setText:@"Voeg een nieuw object toe"];  
     } 
    } 

} 
if(indexPath.section == 3 && control.selectedSegmentIndex == 3){ 

    if([isResponsible count] == 0){ 

     [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
     [[cell textLabel] setText: @"Voeg een nieuwe goal toe"]; 
    } 
    else{ 

     if(indexPath.row < [isResponsible count]) { 


      Goal *goal = (Goal*)[isResponsible objectAtIndex:indexPath.row]; 
      [[cell textLabel] setText:goal.goalNaam]; 

     } 


     if(indexPath.row == [isResponsible count]){ 
      [[cell textLabel] setTextAlignment:UITextAlignmentLeft]; 
      [[cell textLabel] setText: @"Voeg een nieuwe goal toe"]; 


     } 
    } 

} 

代碼頁腳:

@property (nonatomic, retain) IBOutlet UIView *myFooterView; 


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

{ 
    if(section == tableView.numberOfSections - 1) 
    return 50.0f; 

} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 

if(myFooterView == nil) { 
    //allocate the view if it doesn't exist yet 
    myFooterView = [[UIView alloc] init]; 


    //create the button 
    UIButton *footButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

    [footButton setFrame:CGRectMake(110, 10, 100, 30)]; 

    //set title, font size and font color 
    [footButton setTitle:@"Go Home" forState:UIControlStateNormal]; 
    [footButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]]; 

    //set action of the button 
    [footButton addTarget:self action:@selector(clickPressed:) 
     forControlEvents:UIControlEventTouchUpInside]; 

    //add the button to the view 
    [myFooterView addSubview:footButton]; 
} 

//return the view for the footer 
return myFooterView; 

}

分機ra評論:我在不同的視圖中使用相同的頁腳(不同的tableview)只有一個部分,這裏按鈕顯示正確。

+0

你可以發佈添加按鈕到腳註視圖和'cellForRowAtIndexPath'內的代碼的代碼嗎? –

+0

我添加了代碼,你可以給它看看嗎? – Fuzej

回答

0

嘿你可以編寫分段控制&按鈕動態而不是靜態。

例如,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"MyIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    if (indexPath.section == 0) 
    { 
     if (indexPath.row == 0) 
     { 
      //Dynamic Code for Segmented Control 
      [cell.contentView addSubview:segementedControl]; 
     } 
    } 

    ----------- 

    if (indexPath.section == 4) // For Eg. 5 is the last section. You can use your own 
    { 
     if (indexPath.row == 0) 
     { 
      //Dynamic Code for Button 
      [cell.contentView addSubview:button]; 
     } 
    } 
} 

希望它會工作。謝謝。

+0

我不明白這與我的問題有什麼關係?我不想讓他們在我的牢房裏。 – Fuzej

+0

因此,您可以在視圖頂部設置UISegmented控件。然後在View中設置TableView並在底部添加按鈕。無需爲全尺寸進行表視圖。例如: –

+0

分段控制以10和高度 - > 40開始。因此,TableView以 - > 60開頭,高度爲 - > 260。然後在底部添加按鈕。所以滾動將只在TableView內部啓用。謝謝。 –