Static table view inside UIViewController [Xcode 5]

后端 未结 5 1054
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 02:45

I\'m aware of the problem that one is not able to have static table view content in a UIViewController in

I don\'t get a warning/error but he also doesn\'t compile. Is

5条回答
  •  粉色の甜心
    2020-12-05 03:30

    There's a way to improve Can's answer.

    Connect your cells to code not as IBOutlet but as IBOutletCollection. If you name it as e.g. cells your code will look like this, which makes it slightly cleaner:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.cells.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return self.cells[indexPath.row];
    }
    

    The order in which you connect cells to outlet collection will be the order you see when run the app.

    I can think of supporting several sections by linking their cells to several outlet collections.

提交回复
热议问题