2011-02-24 35 views
4

對於自定義表頁腳,我使用下面的代碼的UIButton在表尾無響應

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
    if(editmode) { 
    if(footerView == nil) { 
     //allocate the view if it doesn't exist yet 
     footerView = [[UIView alloc] init]; 

     //we would like to show a gloosy red button, so get the image first 
     UIImage *image = [[UIImage imageNamed:@"button_green.png"] stretchableImageWithLeftCapWidth:8 topCapHeight:8]; 

     //create the button 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [button setBackgroundImage:image forState:UIControlStateNormal]; 

     //the button should be as big as a table view cell 
     [button setFrame:CGRectMake(10, 3, 300, 44)]; 

     //set title, font size and font color 
     [button setTitle:@"Photo" forState:UIControlStateNormal]; 
     [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 

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

     //add the button to the view 
     [footerView addSubview:button]; 
     UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     image = [[UIImage imageNamed:@"button_grey_dark.png"] stretchableImageWithLeftCapWidth:8 topCapHeight:8]; 
     [button2 setBackgroundImage:image forState:UIControlStateNormal]; 

     //the button should be as big as a table view cell 
     [button2 setFrame:CGRectMake(10, 50, 300, 44)]; 

     //set title, font size and font color 
     [button2 setTitle:@"Note" forState:UIControlStateNormal]; 
     [button2.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 

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

     //add the button to the view 
     [footerView addSubview:button2]; 

     //  [button setupAsRedButton]; 
    } 

    //return the view for the footer 
    return footerView; 
    } 
    return nil; 
} 

利用這一點,第一個按鈕響應很好,但是,第二個沒有註冊任何事件。即使該函數不存在,也不會生成空函數錯誤。關於爲什麼UITouchUpInside未被識別的任何想法?

回答

9

Doh !!!

右下面這段代碼,我不得不

// specify the height of your footer section 
- (CGFloat)tableView:(UITableView *)tableView 
heightForFooterInSection:(NSInteger)section { 
    //differ between your sections or if you 
    //have only on section return a static value 
    return 50; 
} 

其中設置了UIView忽略低於50個像素的任何東西。改成100,我很好。