UIButton在iPhone 5S上不显示。

3

我在iOS开发以及开发领域都比较新手。

我正在开发一个时间/记录应用,但遇到了一个奇怪的问题。在我的一个视图控制器上,我有一个UITableView,其中每个单元格都是一个按钮,可以导航到不同的视图控制器。在第一个单元格中,用户应该能够按下UIButton来运行一个方法以开始计时。运行该方法后,它会激活一个第二个UIButton,用户可以按下停止计时。同时,右侧的UILabel显示经过的时间。

到目前为止,这一切都很正常,直到几天前。我下载并开始使用Xcode 5.1 beta 5,并在其中开始开发应用程序。现在,在我的iPhone 5S或任何使用iPhone 5S的测试人员上,UIButtons都不会出现。它可以在iPhone模拟器上和真正的非5S iPhone(包括iPad)上工作。

我想也许是一个64位问题,我查看了我的代码并没有找到任何不能在64位设备上工作的问题。但我看了Apple Developer Video,它说64位设备上的32位应用程序将简单地加载32位的iOS库并像那样运行。因为迄今为止在任何设备上都没有遇到任何问题,所以我还没有在我的应用程序上启用ARM-64。iOS 7.1 SDK在beta 5中是否有一些更改,需要在64位设备上以不同的方式调用tableviews或UIButtons?我甚至在一个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;

感谢您的帮助。

iOS测试版很棘手。尝试将应用程序重新构建为新项目,并将您的工作复制到带有测试版的新项目中,看看是否有效或是否会抛出警告或异常。在使用测试版时,我学到并不是所有问题都得到解决。毕竟这只是一个测试版.. :) - Adrian P
我因为这个确切的问题遇到了困难。在Xcode 5.1和iPhone 5S的GA版本中,这仍然在发生。 - Vinod Vishwanath
1个回答

3

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

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

我不知道为什么之前它们被设置成“弱”的时候能够正常工作,并且在模拟器上也能工作。我只能猜测在iOS 7.1的Beta 5中发生了一些变化 - 我以前是用Beta 3进行构建的。但是,当我改变属性后,我又可以在测试的iPhone 5S设备上看到按钮了。


如果这解决了问题,您应该接受自己的答案。 - Marco
明天之前我无法接受自己的答案。我已经尝试过了。 - bdepaz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接