2011-07-22 79 views
0

我嘗試小夥子在UIButton的一個UIViewController點擊裝載視圖點擊

GehaltVIew.m

#import "GehaltVIew.h" 
#import "Berechnen.h" 

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

    UIView *footerView = [[UIView alloc] init]; 

    UIButton *berechnenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    berechnenButton.frame = CGRectMake(10, 10, 300, 40); 
    [berechnenButton setTitle:@"Berechnen!" forState:UIControlStateNormal]; 
    [berechnenButton addTarget:self action:@selector(berechnenGehalt) forControlEvents:UIControlEventTouchUpInside]; 

    [footerView addSubview:berechnenButton]; 

    return footerView; 
} 


- (void)berechnenGehalt 
{ 
    Berechnen *dvController = [[Berechnen alloc] initWithNibName:@"Berechnen" bundle:nil]; 

    self.view = dvController; 
} 

,但我得到這個錯誤:

2011-07-22 14:51: 59.598研討會應用2 [33791:207] - [Berechnen SETFRAME:]:無法識別的選擇發送到實例0x5d05bd0

回答

2

從這句話:

Berechnen *dvController = [[Berechnen alloc] initWithNibName:@"Berechnen" bundle:nil]; 

在我看來,在Berechnen應該是一個UIViewController,不是UIView,因此下一行應該是:

self.view = dvController.view; 

請,還請注意,在tableView:viewForFooterInSection你可能泄漏footerView。我認爲你應該autorelease footerView:

UIView *footerView = [[[UIView alloc] init] autorelease]; 
+0

謝謝你,它的工作 –

+0

爲什麼不把它標記爲正確的答案呢? – Fredrik