UIButton 未出现在 iPhone 5S 上

2024-05-10

总的来说,我对 iOS 开发和开发还很陌生。

我一直在开发时间/记录保存应用程序,但遇到了一个奇怪的问题。在我的一个视图控制器上,我有一个 UITableView,每个单元格都是一个按钮,可通往不同的视图控制器。在第一个单元格上,用户应该能够按下 UIButton 来运行开始计时的方法。当您运行该方法时,它会激活第二个 UIButton,用户可以按下该按钮来停止计时。虽然这是在单元格右侧的 UILabel 上进行的,但它显示了经过的时间。

到目前为止,它一直运行良好,直到几天前。我下载并开始使用 Xcode 5.1 beta 5,并开始在其中开发应用程序。现在,UIButton 不会出现在我的 iPhone 5S 或任何使用 iPhone 5S 的测试仪上。它适用于 iPhone 模拟器和真正的非 5S iPhone(包括 iPad)。

我认为这可能是 64 位问题,我查看了我的代码,但找不到任何无法在 64 位设备上运行的内容。但我看了一个 Apple 开发者视频,视频中说 64 位设备上的 32 位应用程序将简单地加载 32 位 iOS 库并像这样运行它们。我还没有在我的应用程序上启用 ARM-64,因为到目前为止我在任何设备上都没有遇到任何问题。 iOS 7.1 SDK beta 5 中是否有更改,要求在 64 位设备上以不同方式调用 tableview 或 UIButton?我什至用 64 位模拟器尝试过,它也运行得很好。

我把相关代码放在下面。我是开发新手,非常感谢任何帮助。

//Set Button Properties
self.startTimeButton.frame = CGRectMake(0, 0, 100, 39);
self.startTimeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.startTimeButton setTitle:@"Start Time" forState:UIControlStateNormal];
self.startTimeButton.backgroundColor = [UIColor greenColor];
[self.startTimeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.startTimeButton setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];
[self.startTimeButton addTarget:self action:@selector(startCountingTime) forControlEvents:UIControlEventTouchUpInside];

//Set Button 2 Properties
self.stopTimerOut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.stopTimerOut.frame = CGRectMake(100, 0, 100, 39);
[self.stopTimerOut setTitle:@"Stop Time" forState:UIControlStateNormal];
self.stopTimerOut.backgroundColor = [UIColor redColor];
[self.stopTimerOut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.stopTimerOut addTarget:self action:@selector(stopCountingTime) forControlEvents:UIControlEventTouchUpInside];

//Set Timer Label
self.timerDisplayLabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 0, 60, 40)];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// First Section - Time Section
if (indexPath.section == 0) {
    if (indexPath.row == 0) {
        [cell addSubview:self.startTimeButton];
        [cell addSubview:self.stopTimerOut];
        [cell addSubview:self.timerDisplayLabel];
        [cell addSubview:self.timerActivityDiscloser];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    if (indexPath.row == 1) {
        cell.textLabel.text = @"Manually Enter Time";
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"View Time for Month";
    }
}

这是我的头文件

@property (weak, nonatomic) UIButton *startTimeButton;
@property (weak, nonatomic) UIButton *stopTimerOut;
@property (strong, nonatomic) UILabel *timerDisplayLabel;

感谢您的帮助。


我找到了解决问题的办法。我像这样更改了头文件中的属性:

@property (strong, nonatomic) UIButton *startTimeButton;
@property (strong, nonatomic) UIButton *stopTimerOut;
@property (strong, nonatomic) UILabel *timerDisplayLabel;

我不知道为什么我需要让它们变得“强”,因为它们之前作为“弱”工作得很好并且仍然在模拟器上工作。我只能猜测 iOS 7.1 的 Beta 5 中发生了一些变化 - 我之前是使用 Beta 3 进行构建的。但是一旦我更改了属性,我就可以再次在测试 iPhone 5S 设备上看到按钮。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UIButton 未出现在 iPhone 5S 上 的相关文章

随机推荐