程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> uitableview-從UIView的子類中推入視圖控制器

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

編輯:編程綜合問答
從UIView的子類中推入視圖控制器

創建了一個視圖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;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved