我需要這段代碼添加了一些自定義視圖控制器,其中一些來自的UITableViewController和其他繼承距離的UIViewController:在這種情況下我應該使用繼承嗎?
self.backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 30, 40, 40)];
UIImage *image = [UIImage imageNamed:@"backButton.png"];
[self.backButton setBackgroundImage:image forState:UIControlStateNormal];
[self.view addSubview:self.backButton];
[self.backButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
- (void)backButtonPressed{
[self.navigationController popViewControllerAnimated:YES];
}
我的問題是:什麼是有這一塊最好的方法可用於我的多個視圖控制器的代碼。遺產?如果是這樣,我怎麼能在從不同類繼承的視圖控制器?
你有導航欄顯示嗎?我看到你正在使用導航控制器。如果它顯示在導航欄中,您可以將該按鈕添加到視圖中。 – AdamPro13 2014-10-29 17:44:51
我隱藏了導航欄,這就是爲什麼我需要這個按鈕。 – ZviBar 2014-10-29 17:53:47