我在显示视图时更改方向。但是当我将方向从纵向更改为横向时,cellForRowAtIndexPath内容不会更改。但是当我滚动表格时,方向会发生变化。意味着它无法正常工作。我不知道为什么?对于肖像模式也是如此。任何人都可以帮助我解决这个问题。我的cellForRowAtIndexPath代码显示在enter code here
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [deliveryCases dequeueReusableCellWithIdentifier:cellIdentifier];
// Showing data in table view
d = [deliveryCaseArray objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSArray *subviewArray = cell.contentView.subviews;
for (UIView *view in subviewArray)
{
[view removeFromSuperview];
}
UILabel *randomNumLbl =[[UILabel alloc]initWithFrame:CGRectMake(20, 5, 100 ,50)];
randomNumLbl.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
randomNumLbl.textColor=[UIColor colorWithRed:74.0/255.0 green:144.0/255.0 blue:226.0/255.0 alpha:1];
randomNumLbl.font =[UIFont systemFontOfSize:15]; randomNumLbl.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:randomNumLbl];
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
caseNameLbl =[[UILabel alloc]initWithFrame:CGRectMake(50, -5, 85 ,70)];
}
else
{
if (IS_IPHONE5)
{
caseNameLbl =[[UILabel alloc]initWithFrame:CGRectMake(160, -5, 85 ,70)];
}
else
{
caseNameLbl =[[UILabel alloc]initWithFrame:CGRectMake(140, -5, 85 ,70)];
}
}
caseNameLbl.text = [NSString stringWithFormat:@"%@",d.caseName];
caseNameLbl.textColor=[UIColor colorWithRed:74.0/255.0 green:144.0/255.0 blue:226.0/255.0 alpha:1];
caseNameLbl.font =[UIFont systemFontOfSize:15];
caseNameLbl.numberOfLines = 3;
caseNameLbl.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:caseNameLbl];
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
caseDateLbl =[[UILabel alloc]initWithFrame:CGRectMake(140, 5, 100 ,50)];
}
else
{
if (IS_IPHONE5)
{
caseDateLbl =[[UILabel alloc]initWithFrame:CGRectMake(320, 5, 100 ,50)];
}
else{
caseDateLbl =[[UILabel alloc]initWithFrame:CGRectMake(270, 5, 100 ,50)];
}
}
NSString *dateStr =d.date;
NSString *dateCode = [dateStr substringToIndex:[dateStr length] - 8];
caseDateLbl.text=[NSString stringWithFormat:@"%@",dateCode];
caseDateLbl.textColor=[UIColor colorWithRed:74.0/255.0 green:144.0/255.0 blue:226.0/255.0 alpha:1];
caseDateLbl.font =[UIFont systemFontOfSize:15];
caseDateLbl.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:caseDateLbl];
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
caseStatusLbl = [[UILabel alloc]initWithFrame:CGRectMake(230, -5,85 ,70)];
}
else
{
if (IS_IPHONE5)
{
caseStatusLbl = [[UILabel alloc]initWithFrame:CGRectMake(480, -5,85 ,70)];
}
else
{
caseStatusLbl = [[UILabel alloc]initWithFrame:CGRectMake(410, -5,85 ,70)];
}
}
caseStatusLbl.text = [NSString stringWithFormat:@"%@",d.status];
caseStatusLbl.textColor=[UIColor colorWithRed:74.0/255.0 green:144.0/255.0 blue:226.0/255.0 alpha:1];
caseStatusLbl.font =[UIFont systemFontOfSize:15];
caseStatusLbl.numberOfLines = 3;
caseStatusLbl.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:caseStatusLbl];
[cell setUserInteractionEnabled:YES];
tableView.allowsSelection=YES;
deliveryCases.bounces=YES;
return cell;
}