UIButton没有出现在iPhone 5S上

时间:2022-07-25 21:09:24

I'm kind of new to iOS development and development in general.

总的来说,我对iOS的开发和开发有点陌生。

I've been working on a time/record keeping app and I ran into a weird problem. On one of my view controllers I have a UITableView with each cell being a button that leads to a different view controller. On the first cell the user is supposed to be able to push a UIButton to run a method that starts counting time. When you run that method it activates a second UIButton that the user can push to stop counting time. While this is going on a UILabel on the right hand side of the cell shows the elapsed time.

我一直在开发一个时间/记录保存应用,我遇到了一个奇怪的问题。在我的一个视图控制器中,我有一个UITableView,每个单元格都是一个按钮,它可以指向不同的视图控制器。在第一个单元格上,用户应该能够按下UIButton来运行一个开始计算时间的方法。当你运行那个方法时,它会激活第二个UIButton用户可以按它停止计数时间。而在单元格右边的UILabel上显示了经过的时间。

It has worked fine so far until a few days ago. I downloaded and started using Xcode 5.1 beta 5 and started working on the app in it. Now the UIButtons don't appear on my iPhone 5S or any of my testers that use iPhone 5S. It works on the iPhone Simulator and on real non-5S iPhones including iPad.

直到几天前,它还能正常工作。我下载并开始使用Xcode 5.1 beta 5,并开始使用它。现在UIButtons不会出现在我的iPhone 5S或任何使用iPhone 5S的测试人员身上。它可以在iPhone模拟器上工作,也可以在包括iPad在内的非5s iPhone上工作。

I thought maybe it was a 64-bit problem and I've looked around my code and can't find anything that wouldn't work on 64-bit devices. But I watched an Apple Developer Video that says that 32-bit apps on 64-bit devices will simply load the 32-bit iOS libraries and run them like that. I haven't enabled ARM-64 on my app yet, since so far I haven't had any problems with it on any device. Has there been a change in the iOS 7.1 SDK in beta 5 that requires tableviews or UIButtons to be called differently on 64-bit devices? I even tried it with a 64-bit simulator and it works fine on it too.

我认为这可能是一个64位的问题,我检查了我的代码,没有发现任何在64位设备上不能工作的东西。但我看过一段Apple Developer的视频,视频说64位设备上的32位应用程序只需要加载32位的iOS库,然后像这样运行。我还没有在我的应用上启用ARM-64,因为到目前为止我在任何设备上都没有遇到任何问题。在beta 5中,iOS 7.1 SDK是否有变化,需要在64位设备上调用tableview或UIButtons ?我甚至尝试了一个64位的模拟器,而且它也适用于它。

I put the relevant code below. I'm a newbie at development and would appreciate any help.

我把相关的代码放在下面。我是一个发展中的新手,希望得到任何帮助。

//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";
    }
}

And here is my header file

这是我的头文件

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

Thank you for your help.

谢谢你的帮助。

1 个解决方案

#1


3  

I found a solution to the problem. I changed the properties in the header file like this:

我找到了解决这个问题的办法。我在头文件中修改了属性如下:

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

I don't know why I would need to make them "Strong" when they worked fine as "Weak" before and still worked on the simulator. I can only guess that something has changed in Beta 5 of iOS 7.1 - I was previously building with Beta 3. But as soon as I changed the properties I could once again see the buttons on the test iPhone 5S devices.

我不知道为什么我需要让他们变得“强大”,当他们之前表现得很好,但仍然在模拟器上工作。我只能猜测ios7.1的Beta 5发生了变化——我之前用的是Beta 3。但一旦我改变了属性,我就可以再次看到测试iPhone 5S设备上的按钮。

#1


3  

I found a solution to the problem. I changed the properties in the header file like this:

我找到了解决这个问题的办法。我在头文件中修改了属性如下:

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

I don't know why I would need to make them "Strong" when they worked fine as "Weak" before and still worked on the simulator. I can only guess that something has changed in Beta 5 of iOS 7.1 - I was previously building with Beta 3. But as soon as I changed the properties I could once again see the buttons on the test iPhone 5S devices.

我不知道为什么我需要让他们变得“强大”,当他们之前表现得很好,但仍然在模拟器上工作。我只能猜测ios7.1的Beta 5发生了变化——我之前用的是Beta 3。但一旦我改变了属性,我就可以再次看到测试iPhone 5S设备上的按钮。