how to push view controller from a UIView's subclass

后端 未结 2 1477
再見小時候
再見小時候 2021-01-13 19:18

I created a view \"CategoryTableView\" that subclass from UIView. And CategoryTableView contains a UITableView. I added <

2条回答
  •  温柔的废话
    2021-01-13 19:49

    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;
    

提交回复
热议问题