gpt4 book ai didi

objective-c - xcode 崩溃后,某些按钮的标题为空或被部分截断

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:11 27 4
gpt4 key购买 nike

这似乎是 XCode 4: some button titles not visible in iOS simulation 的部分转发但他们的问题没有得到回答。

请轻点,我对此很陌生。

我已经按照 stamford 讲座系列实现了一个基于堆栈的计算器程序,但我的一些按钮在模拟器中显示为空或半截断。每次我运行 sim 时,相同的按钮都会执行此操作,但如果我移动任何按钮,它会改变受影响的按钮。通常是底部的。

这里的第一个例子:http://i.imgur.com/YpC1f.png - 查看底行按钮如何显示不正确?如果我将这些按钮中的任何一个调高,它将不显示任何标题,但所有其他四个按钮将正确显示。

我认为它可能离底部太近了,或者那些按钮坏了,或者类似的。所以我删除了整个底行,缩小了所有内容,然后重新创建了这些按钮,现在我得到了四个带有空白标题和两个被截断的按钮:http://i.imgur.com/kM1Rb.png

请注意,所有按钮仍然按预期工作,只是显示不正确。

我做错了什么吗?任何建议表示赞赏。

编辑:来自 Controller 的完整代码:

#import "CalculatorViewController.h"
#import "CalculatorBrain.h"

@interface CalculatorViewController()
@property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
@property (nonatomic, strong) CalculatorBrain *brain;
- (void)updateStackDisplay:(NSString *)value;
@end

@implementation CalculatorViewController

@synthesize display = _display;
@synthesize stackDisplay = _stackDisplay;
@synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;
@synthesize brain = _brain;

- (CalculatorBrain *)brain {
if (!_brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}

- (void)updateStackDisplay:(NSString *)value {
// if there's nothing sent so far, just initialise it
if (self.stackDisplay.text.length == 0) {
self.stackDisplay.text = value;
return;
}
// This part is a little confusing. Extra assignment asked for = to be added to the end of the stack label if an operation was pressed.
// Here I check for = at the end of the label and remove it so it's only displayed once. If "=" is being passed (done by the operation itself), it will be added back on right at the end of this function.
if ([self.stackDisplay.text rangeOfString:@"="].location == (self.stackDisplay.text.length - 1)) {
// .location starts at zero, .length doesn't.
self.stackDisplay.text = [self.stackDisplay.text substringToIndex:[self.stackDisplay.text length]-1];
}
// If we add a space after remove the = we'll end up with double space. Hence the else if, not if.
else if (!self.userIsInTheMiddleOfEnteringANumber) {
self.stackDisplay.text = [self.stackDisplay.text stringByAppendingString:@" "];
}
self.stackDisplay.text = [self.stackDisplay.text stringByAppendingString:value];
}

- (IBAction)digitPressed:(UIButton *)sender {
NSString *digit = sender.currentTitle;
if ([digit isEqualToString:@"."]) {
if ([self.display.text rangeOfString:@"."].location != NSNotFound) {
return;
}
else {
if (!self.userIsInTheMiddleOfEnteringANumber) digit = @"0.";
}
}
[self updateStackDisplay:digit];
if (self.userIsInTheMiddleOfEnteringANumber) {
self.display.text = [self.display.text stringByAppendingString:digit];
}
else {
self.display.text = digit;
self.userIsInTheMiddleOfEnteringANumber = YES;
}
}

- (IBAction)operationPressed:(UIButton *)sender {
if (self.userIsInTheMiddleOfEnteringANumber) [self enterPressed];
[self updateStackDisplay:sender.currentTitle];
[self updateStackDisplay:@"="];
double result = [self.brain performOperation:sender.currentTitle];
NSString *resultString = [NSString stringWithFormat:@"%g", result];
self.display.text = resultString;
}

- (IBAction)enterPressed {
if (self.userIsInTheMiddleOfEnteringANumber) {
self.userIsInTheMiddleOfEnteringANumber = NO;
}
[self.brain pushOperand:[self.display.text doubleValue]];
}

- (IBAction)clearPressed {
self.stackDisplay.text = @"";
[self.brain clearStack];
self.userIsInTheMiddleOfEnteringANumber = NO;
self.display.text = @"0";
}

@end

最佳答案

我得到了一个可能类似的错误,其中一些 UIButtons 有空文本,尽管通过输出 titleLabel.text 得到了正确的文本值。我删除了按钮并添加了与之前在 Storyboard中相同的按钮。然后就成功了。

关于objective-c - xcode 崩溃后,某些按钮的标题为空或被部分截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13003804/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com