简体   繁体   English

如何以编程方式在UIview Xib文件上加载UItableList

[英]How to load UItableList Programatically on UIview xib files

Hi i am very new for ios and in my app i am loading UITableView programmatically on UIView xib file but using my below code UItableList not adding on my UIView xib file what wrong i have done here please help me some one 嗨,我是iOS的新手,在我的应用程序中,我以编程方式在UIView xib文件上加载UITableView,但使用下面的代码UItableList不在我的UIView xib文件上添加了我在这里做错了什么,请帮助我

mycode:- mycode:-

  #import "FaqQuestionsClass.h"

    @implementation FaqQuestionsClass
    {
        BackGroundClass * Bg;
        UITableView * tableList;
    }
    @synthesize mainView;

    -(instancetype)initWithFrame:(CGRect)frame{

        if (self = [super initWithFrame:frame]) {

            [self loadingView];
        }
        return self;
    }

    - (void)awakeFromNib{

        [super awakeFromNib];

        [self loadingView];
    }

    -(void)loadingView{

        Bg = [[BackGroundClass alloc]init];

        tableList = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableList.translatesAutoresizingMaskIntoConstraints = NO;
        tableList.dataSource=self;
        tableList.delegate=self;
        tableList.backgroundColor = [UIColor orangeColor];
        tableList.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        tableList.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableList.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        [tableList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
        [mainView addSubview:tableList];
    }

    //UITableView Delegate Methods:-

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return  10;
    }
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

        return 1;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier   forIndexPath:indexPath] ;

        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.textLabel.text = @"hello";

        return cell;
    }

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        return 50;
    }

    @end

You are setting the wrong frame for tableview. 您为表格视图设置了错误的框架。 CGRectZero means that the table view is not visible on mainView . CGRectZero意味着表视图在mainView上不可见。 Update the below line 更新下面的行

tableList = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];

with:- 与:-

tableList = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM