【发布时间】:2016-10-17 12:00:45
【问题描述】:
我正在使用带有 TableViewCell 的 TableView。我以编程方式向单元格添加了 ImageView、Text 和 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 我已经添加了代码。
-
这段代码你在哪里写的?它可能会运行不止一次。
-
这段代码在哪里?
-
代码在 cellForRowAtIndexPath 中。
标签: ios objective-c uitableview uibutton uiinterfaceorientation