從UIView的子類中推入視圖控制器

原問題來自於CSDN問答頻道,更多解決方案見:http://ask.csdn.net/questions/1972

問題描述:

創建了一個視圖CategoryTableView,繼承UIView。CategoryTableView包含了一個UITableView。我將CategoryTableView 作爲子類添加到HomeViewController 中,HomeViewController 是UIViewController的子類。目前,我需要在didSelectRowAtIndexPath 執行時推入一個新的controller。但是在CategoryTableView中怎麼推入或顯示另一個視圖控制器?

不能在CategoryTableView去導航控制器。

解決方案:

CategoryTableView.h

@property (retain, nonatomic) parentViewController *parent; //create one property for parent view like this

CategoryTableView.m

@sythesize parent;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [parent.navigationController . . .]; // preform action
    //OR..
    [parent presentModalViewController: . . .]; // present modal view
}

parent.m

//while calling your CategoryTableView assign self to your parent object

    CategoryTableView *tblView = [CategoryTableView alloc] init];
    tblView.parent = self;


發佈了95 篇原創文章 · 獲贊 125 · 訪問量 33萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章