【发布时间】:2011-03-11 01:37:01
【问题描述】:
在处理 Mark 和 LeMarche 提供的示例时,我遇到了许多情况无法按预期工作。例如,第 4 章讨论了用图像“增加按钮”。尽管我遵循了原始说明和一些变通方法 [1,2,3],但我似乎无法在按钮上拉伸图像。
如何确定在返回 void 的 Objective C 方法中遇到的错误? (恕我直言,一个无用的范例)。猜测罪魁祸首或错误是无用的浪费时间,而且对我来说效果不佳。
很抱歉,我很机智,我已经厌倦了所有的 printf、NSLogs 和猜测。这不是开发程序的方法。
杰夫
[1]Resizing an image with stretchableImageWithLeftCapWidth
[2]stretchableImageWithLeftCapWidth:topCapHeight doesn't work in initWithCoder: of UIImageView subclass
[3]iPhone stretchableImageWithLeftCapWidth only makes "D"s
// Source code from Mark and LeMarch ('Beginning iPhone 4 Programming', Chapter 4, pp. 99-100)
// added for completeness. The same code is presented in 'Beginning iPhone 3 Programming'.
// The button type is 'Custom', and the mode is 'Scale to Fill'. Trying to use TIFFs,
// removing Alpha channels, resizing buttons so their size is image.height+1, etc - no joy.
// The buttons were provided by Apple in their UICatalog example (http://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html).
// I've also tried to assign the image to a single button in case the resource cannot be shared.
// Finally, no ASSERTs fire (and no exceptions are thrown), so all should be OK (yea, right).
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* whiteButton = [UIImage imageNamed:@"whiteButton.png"];
ASSERT(whiteButton != nil);
UIImage* strechableWhiteButton = [whiteButton stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
ASSERT(strechableWhiteButton != nil);
[changeSrcFileButton setBackgroundImage:strechableWhiteButton forState:UIControlStateNormal];
[changeDestFileButton setBackgroundImage:strechableWhiteButton forState:UIControlStateNormal];
UIImage* blueButton = [UIImage imageNamed:@"blueButton.png"];
ASSERT(blueButton != nil);
UIImage* strechableBlueButton = [blueButton stretchableImageWithLeftCapWidth:12 topCapHeight:0];
ASSERT(strechableBlueButton != nil);
[changeSrcFileButton setBackgroundImage:strechableBlueButton forState:UIControlStateHighlighted];
[changeDestFileButton setBackgroundImage:strechableBlueButton forState:UIControlStateHighlighted];
}
【问题讨论】:
-
如果猜测问题对您来说是浪费时间,想象一下您甚至不显示代码对我们来说是多么困难! ;-) 我知道您可能会问的不仅仅是您给出的示例,但是为什么要三个参考?
-
嗨 Caleb - 我对一般情况更感兴趣(即,当出现问题时如何在某处检索错误代码)。这样,我可以解决我的大部分问题,而不会浪费人们在 Stack Overflow 上的时间。杰夫
-
ASSERT(changeSrcFileButton != nil);在哪里? -
嗨fluchtpunkt - 好点。它将被添加(它也是一个 IBOutlet,以防万一)。我可以告诉你,它不是零。杰夫
-
忘记连接一些 IBOutlets 的程序员的遗言? - “我可以告诉你,它不是零”。 - 开个玩笑。但如果他们真的不是零,我可以部分理解你的咆哮。
标签: iphone objective-c ios