Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 滚动时自定义UITableViewCell布局_Ios_Objective C_Xcode_Scroll_Custom Cell - Fatal编程技术网

Ios 滚动时自定义UITableViewCell布局

Ios 滚动时自定义UITableViewCell布局,ios,objective-c,xcode,scroll,custom-cell,Ios,Objective C,Xcode,Scroll,Custom Cell,我有一个自定义单元格的UITableView。因为我无法向标签添加约束,所以我尝试以编程方式进行此操作。现在,除了开始滚动外,一切都正常了。不知何故,layoutsubviews方法被忽略或重置 TableViewController.m SubjectCell.m 使subjectLabel可公开访问,并在ViewController本身内更改其框架 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex

我有一个自定义单元格的UITableView。因为我无法向标签添加约束,所以我尝试以编程方式进行此操作。现在,除了开始滚动外,一切都正常了。不知何故,layoutsubviews方法被忽略或重置

TableViewController.m

SubjectCell.m

使subjectLabel可公开访问,并在ViewController本身内更改其框架

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

    SubjectCell *cell = (SubjectCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];

    cell.subjectLabel.text = [tentamenArray objectAtIndex:currentRow][@"SUMMARY"];

    CGSize screen = [UIScreen mainScreen].bounds.size;
    [cell.subjectLabel setFrame:CGRectMake(15, 15, screen.width - 70, 20)];

    return cell;
}
您是否尝试改为使用-voidPrepareforuse方法?
- (void) layoutSubviews {
    [super layoutSubviews];
    CGSize screen = [UIScreen mainScreen].bounds.size;
    [_subjectLabel setFrame:CGRectMake(15, 15, screen.width - 70, 20)];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    SubjectCell *cell = (SubjectCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];

    cell.subjectLabel.text = [tentamenArray objectAtIndex:currentRow][@"SUMMARY"];

    CGSize screen = [UIScreen mainScreen].bounds.size;
    [cell.subjectLabel setFrame:CGRectMake(15, 15, screen.width - 70, 20)];

    return cell;
}