[英]Displaying data in the tableView with custom view in iOS
In my app, I'm having a tableview, which I access using section and not by row. 在我的应用程序中,我有一个表视图,该视图是使用section而不是按行访问的。
I have used custom views on section section, the custom view contains few labels 我在section区域使用了自定义视图,该自定义视图包含一些标签
In my cellForRow at index, 在索引的cellForRow中,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
viewOrderPage=[[ViewOrder alloc]init];
static NSString * cellIdentifier=@"Mytable";
UITableViewCell * cell;
if(cell==nil)
{
cell=[contentTable dequeueReusableCellWithIdentifier:cellIdentifier];
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
viewOrderPage=[[ViewOrder alloc]initWithFrame:CGRectMake(0, 0, 310, 60)];
viewOrderPage.tag=111;
[cell.contentView addSubview:viewOrderPage];
}
else
{
viewOrderPage=(ViewOrder *)[cell.contentView viewWithTag:111];
}
viewOrderPage.productName.text=@"aaa";
return cell;
}
But the value is not getting displayed in the cell. 但是该值未显示在单元格中。
viewOrderPage is the object of the customview(ViewOrder) and productName is a label in the view
Modify the code.. 修改代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellIdentifier=@"Mytable";
ViewOrder * cell= (ViewOrder *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
[[NSBundle mainBundle] loadNibNamed:@"ViewOrder" owner:self options:nil];
cell=self.vieworder;
}
NSString * str=[NSString stringWithFormat:@"%@",[productArray objectAtIndex:indexPath.row]];
NSLog(@"%@",str);
cell.productName.text=str;
return cell;
}
Hope it helps you.. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.