Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
Iphone 方向更改时,更改与xib文件连接的自定义UITableViewCell中标签的位置_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone 方向更改时,更改与xib文件连接的自定义UITableViewCell中标签的位置

Iphone 方向更改时,更改与xib文件连接的自定义UITableViewCell中标签的位置,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有一个自定义的UITableviewCell xib,与我的uitableview连接,我将这样做: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MyCell"; UITableViewCell *cell = [tableView dequeueReusa

我有一个自定义的UITableviewCell xib,与我的uitableview连接,我将这样做:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];

    cell = myCell;
    self.myCell = nil;
}

[self configureCell:cell atIndexPath:indexPath];
return cell;
}
然后,当更改设备的方向时,我希望更改自定义UITableViewCell中某些元素的位置,因此在此方法中:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {

    CGRect myframe = CGRectMake(600, self.arrowLabel.frame.origin.y, self.arrowLabel.frame.size.width, self.arrowLabel.frame.size.height);
        self.arrowLabel.frame = myframe;
} else {

    CGRect myframe = CGRectMake(400, self.arrowLabel.frame.origin.y, self.arrowLabel.frame.size.width, self.arrowLabel.frame.size.height);
        self.arrowLabel.frame = myframe;
}
}

我更改了与UITableViewCell xib连接的箭头标签的frame.origin.y和frame.origin.y,但只更改了tableview最后一行的位置,另一行中的另一个标签保持在相同的位置,因此我的问题是如何重新加载表视图?…我还尝试了[self.tableview reloadData];。。。但是不起作用……有什么想法吗?

您可能想尝试将帧更改代码放入
单元格中,以获得行索引路径。基本上,在该方法中,您有如下内容:

if (portrait) {
    // use portrait frames
} else {
    // use landscape frames
}
然后在您的
willRotate
方法中,您可以调用
[tableView reloadData]

编辑:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

for (UITableViewCell *cell in [tableView visibleCells]) {

    if (portrait) {
        CGRect myframe = CGRectMake(600, cell.arrowLabel.frame.origin.y, cell.arrowLabel.frame.size.width, cell.arrowLabel.frame.size.height);
        cell.arrowLabel.frame = myframe;
    } else {
        CGRect myframe = CGRectMake(400, cell.arrowLabel.frame.origin.y, cell.arrowLabel.frame.size.width, cell.arrowLabel.frame.size.height);
        cell.arrowLabel.frame = myframe;
    }
}
}

什么变化?…我已经说过我也尝试过重载调用cellrowforindexpath方法的数据…不,我的意思是在
cellForRowAtIndexPath
方法中,根据方向指定要使用的帧。然后在您的
willRotate
中,您可以调用
重新加载数据
。也许可以将您在
willrotateTocationInterfaceOrientation
中所做的操作用
包装为(在[tableView visibleCells]中的UITableViewCell*单元格)
?希望这将适用于所有单元格。我还对UITableViewCell进行了子类化,因为我使用了xib文件和(tableView visibleCells中的UITableViewCell*单元格)不给我连接到单元格的IBOutlet,我必须使用标记,但我写下这不是更好的选择,所以我对它进行了子类化,然后在中使用(MyCell*单元格)[tableView visibleCells])…感谢您的提示!在我的情况下,我现在正在通过按钮扩展(增加单元格高度)自定义单元格,当我们在will rotate方法中重新加载tableView时,所有单元格都将正确重绘,这将丢失扩展单元格的状态,对吗??:(