- (void)viewDidLoad {
[super viewDidLoad];
menuArray=[[NSMutableArray alloc]initWithObjects:@"Address",@"Restaurants",@"Deals",@"Orders",@"Account",@"Address Book",@"Settings",@"Live Chat",@"Info",nil];
tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, menuSubView.frame.size.height, self.view.frame.size.width-80, self.view.frame.size.height-menuSubView.frame.size.height)];
tableView.delegate=self;
tableView.dataSource=self;
[self.view addSubview:tableView];
}
和其他方法如下-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return menuArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reusableIdentifier=@"Cell4";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableIdentifier];
}
cell.textLabel.text=[menuArray objectAtIndex:indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70;
}
然而,当我运行程序时,我能够看到所需的表格 View 。但是当我滚动浏览它时,表格的数据消失了,只剩下空白的表格 View 。谁能帮我?提前致谢。
最佳答案
--> 我感谢以上回答。
--> 请在“cellForRowAtIndexPath”方法中尝试这一行...!
--> 有时会发生。我过去用这条线解决了这个问题。我希望它对你有用。
UITableViewCell *cell = [self.tblView dequeueReusableCellWithIdentifier:@"Cell4" forIndexPath:indexPath];
关于ios - 我以编程方式创建了一个 TableView ,如下所示 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40401735/