小编Dev*_*Dev的帖子

iOS tableView没有填充数据

有人可以向我解释为什么这没有在viewController中填充tableView吗?我可以使其在UITableViewController中工作,但是当我制作带有tableView的UIViewController时,它不会填充数据。在我的情节提要中,我创建了一个具有tableview和table view单元格的视图控制器。当我运行程序时,我得到的只是我的空tableView。但是它在UITableViewController中很好用

。H

   //MainViewController.h
    #import <UIKit/UIKit.h>

    @interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
    {
        NSArray *topItems;
        NSMutableArray *subItems; // array of arrays

        int currentExpandedIndex;
    }
    @property (strong, nonatomic) IBOutlet UITableView *tableView;


    @end
Run Code Online (Sandbox Code Playgroud)

.m

    ///MainController.m
    #import "MainViewController.h"

    #define NUM_TOP_ITEMS 5
    #define NUM_SUBITEMS 6

    @interface MainViewController ()

    @end

    @implementation MainViewController

    - (id)init {
        self = [super init];

        if (self) {
            topItems = [[NSArray alloc] initWithArray:[self topLevelItems]];
            subItems = [NSMutableArray new];
            currentExpandedIndex = -1;

            for (int i = 0; i < [topItems count]; i++) …
Run Code Online (Sandbox Code Playgroud)

uitableview ios

2
推荐指数
1
解决办法
1528
查看次数

标签 统计

ios ×1

uitableview ×1