adding a UITableView programmatically to a UIViewController

前端 未结 5 1315
栀梦
栀梦 2021-02-02 17:37

I\'m loading a UIViewController into one of my Nav controller\'s hierarchies, which will contain some text and some images. At the bottom, I will want to create a expandable and

5条回答
  •  失恋的感觉
    2021-02-02 18:14

    /************************************************/
    /************* MyCustomController.m *************/
    /************************************************/
    
    @interface MyCustomController () 
    @property (nonatomic, strong) UITableView *tableView;
    @end
    
    @implementation MyCustomController
    
    - (id)initWithNibName:(NSString*)nibName bundle:(NSString*)bundleName
    {
       self = [super initWitNibName:nibName bundle:bundleName];
       if (self)
       {
           self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
           tableView.datasource = self; 
           tableView.delegate = self;
           [self.view addSubview:self.tableView];
       }
    
       return self;
    }
    
    #pragma mark - UITableViewDataSource Methods
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // return number of rows
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // return cell
    }
    
    #pragma mark - UITableViewDelegate Methods
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        // handle table view selection
    }
    
    @end
    

提交回复
热议问题