我正在使用帶有TableViewCell的TableView。我以編程方式向單元添加了ImageView,Text和uibutton。按鈕的框架對於縱向和橫向方向設置不同。但是當設備從縱向旋轉到橫向時,顯示的是兩個按鈕而不是一個。設備旋轉時在TableView Cell中顯示的兩個uibutton
我試圖刪除按鈕時,在橫向模式按鈕不工作。
switch ([indexPath section])
{
case 0:
{
cell.imageView.image = [UIImage imageNamed:@"active.png"];
cell.textLabel.text = @"Application Name";
self.uninstallApplicationButton = [[UIButton alloc] init];
self.uninstallApplicationButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.uninstallApplicationButton setTitle:@"Install" forState: UIControlStateNormal];
[self.uninstallApplicationButton setBackgroundColor:[UIColor brownColor]];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (device == UIUserInterfaceIdiomPhone)
{
if (UIInterfaceOrientationIsLandscape(orientation))
{
self.uninstallApplicationButton.frame = CGRectMake(490.0, 25.0, 65.0, 30.0);
}
else if(UIInterfaceOrientationIsPortrait(orientation))
{
self.uninstallApplicationButton.frame = CGRectMake(250.0, 25.0, 65.0, 30.0);
}
}
else if(device == UIUserInterfaceIdiomPad)
{
self.uninstallApplicationButton.frame = CGRectMake(600.0, 25.0, 150.0, 30.0);
}
}
[cell.contentView addSubview:uninstallApplicationButton];
break;
請包括相關的代碼。 – Caleb
@Caleb我添加了代碼。 – Amon
你在哪裏寫這段代碼?它可能會運行多次。 – Desdenova