UIButton doesn't appear on iPhone 5S

狂风中的少年 提交于 2019-12-23 16:22:42

问题


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

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.

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.

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.

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:


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.



来源:https://stackoverflow.com/questions/21691264/uibutton-doesnt-appear-on-iphone-5s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!