2010-10-21 32 views
23

Tôi đang cố tạo chế độ xem tùy chỉnh cho footerView UITableView có nút trong đó. Tôi có thể thấy nó ở đó, nhưng khi tôi chạm vào nó, không có gì xảy ra ... bạn có thể xem những gì là sai ở đây:UITableView footerView với nút, nút không hoạt động

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    if(self.tableView.tableFooterView == nil) { 
     //allocate the view if it doesn't exist yet 
     UIView *footerView = [[UIView alloc] init]; 

     //create the button 
     UIButton *addNewBtn = [UIButton buttonWithType:UIButtonTypeCustom];  
     //the button should be as big as a table view cell 
     [addNewBtn setFrame:CGRectMake(0, 0, 320, [AddMerchantTVC cellHeight])]; 

     //set title, font size and font color 
     [addNewBtn setTitle:@"Add New" forState:UIControlStateNormal]; 
     [addNewBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [addNewBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
     [addNewBtn addTarget:self action:@selector(addNew:) forControlEvents:UIControlEventTouchUpInside]; 

     UIImageView *cellGradient = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellGradient.png"]]; 
     cellGradient.frame = CGRectMake(0, 54, 320, 16); 
     [footerView addSubview:cellGradient]; 

     //add the button to the view 
     [footerView addSubview:addNewBtn]; 
     footerView.userInteractionEnabled = YES; 
     self.tableView.tableFooterView = footerView; 
     self.tableView.tableFooterView.userInteractionEnabled = YES; 

     [footerView release]; 
     [cellGradient release]; 
} 

- (void)addNew:(id)sender { 
    // This is never called 
    NSLog(@"Touched."); 
} 

Trả lời

36

Bạn' không đặt khung của footerView. Đặt khung của footerView thành ít nhất là cao bằng nút nếu không chạm sẽ không được chuyển xuống nút.

+0

Đó là nó. Cảm ơn bạn! –

+1

Điều này làm việc cho tôi khi tôi thực hiện '- (CGFloat) tableView: (UITableView *) tableView heightForFooterInSection: (NSInteger) phần; 'để chỉ định chiều cao chân trang. –

+0

Điều đó cũng làm việc cho tôi, cảm ơn bạn! –

-8

Tạo một lớp con của UIView và bao gồm các phương pháp:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    return [super hitTest:point withEvent:event]; 
} 

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { 
    return [super pointInside:point withEvent:event]; 
} 
+0

Tôi có thực sự cần một lớp con của UIView để thực hiện điều này ? Nếu vậy, đó là gây phiền nhiễu. –

0

Bạn cần phải thiết lập sectionFooterHeight tài sản của tableView trước khi cuộc gọi đến viewForFooterInSection xảy ra (không thể làm điều đó trong phương pháp viewForFooterInSection).

+0

Đặc biệt nếu bạn sử dụng XIB để xây dựng UIView, bạn cần phải thực hiện chức năng này –

7
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
    return 50.0f; 
} 

đưa phương pháp này trong lớp học của bạn vấn đề của bạn sẽ giải quyết .....

1

làm việc của nó đối với tôi tôi chỉ cần thêm

footerView.frame =CGRectMake(0, 300, 100, 100); 
Các vấn đề liên quan