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
#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
. Update the below line
tableList = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
with:-
tableList = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.