Question

If I launch the app with landscape mode, co-ordinates for buttonList and buttonAttachmentare allocated and set for landscape whose co-ordinates do not change when rotated to portrait.

Similarly, if I launch the app with portrait mode, co-ordinates for buttonList and buttonAttachmentare allocated and set for portrait whose co-ordinates do not change when rotated to landscape.

I have used custom cells and auto layout is unchecked. I have set tags for the button so couldn't mention co-ordinates in the custom tableViewCell class. How do I fix this? Here's my code in 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
                    }
                }
Était-ce utile?

La solution

As per the comments -

How are you managing orientation changes (what notifications,methods have you implemented)? Your table view needs to be told to reloadData after an orientation change happens.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top