无法在uitableViewCell中设置横向坐标

时间:2014-01-02 10:51:53

标签: ios uitableview uiinterfaceorientation

如果我使用横向模式启动应用,则buttonListbuttonAttachment的坐标将被分配并设置为横向,其坐标在旋转为纵向时不会更改。

同样,如果我以纵向模式启动应用程序,则buttonListbuttonAttachment的坐标将被分配并设置为纵向,其坐标在旋转到横向时不会改变。

我使用过自定义单元格并且未选中自动布局。我为按钮设置了标签,因此无法在自定义tableViewCell类中提及坐标。我该如何解决?这是cellForRowAtIndexPath

中的代码
 //static NSString *cellId = @"collabId";
        //emptyCell *cell = (emptyCell *)[self.tableViewJoined dequeueReusableCellWithIdentifier:cellId];

        static NSString *cellId = Nil;
            if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
            {
                cellId = @"collabIdPhone";
            }
            else
            {
                UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
                if (orientation == UIDeviceOrientationPortrait)
                {
                    cellId = @"collabIdIPadPortrait";
                }
                else
                {
                    cellId = @"collabIdIPadLandscape";
                }
            }
            emptyCell *cell = (emptyCell *)[self.tableViewJoined dequeueReusableCellWithIdentifier:cellId];
            if(!cell)
            {
                NSArray *nib;
                UIButton *buttonList;
                UIButton *buttonAttachment;
                if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
                {
                    nib = [[NSBundle mainBundle] loadNibNamed:@"emptyCell" owner:self options:nil];
                    buttonList = [[UIButton alloc] initWithFrame:CGRectMake(199, 0, 30, 25)];
                    buttonAttachment = [[UIButton alloc] initWithFrame:CGRectMake(290, 0, 30, 25)];
                }
                else
                {
                   UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
                    if (orientation == UIDeviceOrientationPortrait)
                    {
                        nib = [[NSBundle mainBundle] loadNibNamed:@"emptyCell_iPad" owner:self options:nil];
                        buttonList = [[UIButton alloc] initWithFrame:CGRectMake(452, 0, 62, 25)]; 
                        buttonAttachment = [[UIButton alloc] initWithFrame:CGRectMake(650, 0, 98, 25)];
NSLog(@"| | | |"); //not invoked when rotated from landscape to portrait
                    }
                    else
                    {
                        nib = [[NSBundle mainBundle] loadNibNamed:@"emptyCell_iPad_Landscape" owner:self options:nil];
                        buttonList = [[UIButton alloc] initWithFrame:CGRectMake(591, 0, 81, 24)];
                        buttonAttachment = [[UIButton alloc] initWithFrame:CGRectMake(850, 0, 128, 24)];
NSLog(@"- - - - -"); //not invoked when rotated from portrait to landscape
                    }
                }

1 个答案:

答案 0 :(得分:1)

根据评论 -

您如何管理方向更改(您实施了哪些通知,方法)?在方向更改发生后,您的表格视图需要被告知 reloadData