1

first image with home button problem second image with bar

I have two problems with my tableview, namely, the "Go Home" button from the tablefooterview is showing up (in the middle of the screen) when the end of the tableview isn't reached yet. As you can see in the first picture, the home button is occurring in the middle of the screen, what I don't want. It has to stay at the bottom of the table.

My second problem is the segmented control, which is normally positioned at the top of the view, is reoccuring in one my cells, where it doesn't belong. I've made sure cell reusidentifier is disabled.

Cells are just filled with text, so I don't see why the segmented control is showing up.

EDIT: Code added

Code for filling up Cells: (just a piece of it, but it's just other text in another cell, nothing changes)

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"];


        }
    }

}

Code for the footer:

    @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;

}

Extra comment: I'm using the same footer in a different view (different tableview) with only one section, and here the button is showing correctly.

Fuzej
  • 97
  • 1
  • 11

1 Answers1

0

Hey You can code for segmented control & button dynamically instead of putting static.

For Eg.

- (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];
        }
     }
 }

Hopefully It'll work. Thanks.

Manann Sseth
  • 2,745
  • 2
  • 30
  • 50
  • I don't understand what this has to do with my question ? I don't want either of them in my cells. – Fuzej Jan 11 '13 at 12:49
  • So you can set UISegmented Control on Top of the View. Then Set TableView in View & Finally Add Button on Bottom. No need to take Table View for Full Size. – Manann Sseth Jan 12 '13 at 03:53
  • For Eg. Segmented Control Starts with 10 & height -> 40. So TableView Starts with -> 60 & take size of height around -> 260. Then Add Button at bottom. So Scrolling will be enabled inside only TableView. Thanks. – Manann Sseth Jan 12 '13 at 03:56
  • Thanks for your advice, although I think There has to be an easier way, no? – Fuzej Jan 12 '13 at 20:09
  • Am I doing something wrong ? I'm sure your solution will work but that's just walking around the problem instead of handling it. – Fuzej Jan 12 '13 at 20:45