我是新來的objective-c,我發現我不知道如何正確地聲明文本屬性on一些給定的標籤等於原始字符串值。我不確定是否需要將標籤轉換爲NSString,或者是否需要直接修改我的斷言語句。如何聲明一個UILabel.text屬性等於NSString的一個實例在objective-c
@interface MoreTest : SenTestCase {
MagiczzTestingViewController* controller;
}
- (void) testObj;
@end
@implementation MoreTest
- (void) setUp
{
controller = [[MagiczzTestingViewController alloc] init];
}
- (void) tearDown
{
[controller release];
}
- (void) testObj
{
controller.doMagic;
STAssertEquals(@"hehe", controller.label.text, @"should be hehe, was %d instead", valtxt);
}
@end
我doMagic方法的實現低於
@interface MagiczzTestingViewController : UIViewController {
IBOutlet UILabel *label;
}
@property (nonatomic, retain) UILabel *label;
- (void) doMagic;
@end
@implementation MagiczzTestingViewController
@synthesize label;
- (void) doMagic
{
label.text = @"hehe";
}
- (void)dealloc {
[label release];
[super dealloc];
}
@end
,當我修改斷言,以原始的NSString比較的工具,但是當我試圖捕捉文本值(假設它的構建是好的NSString類型)它失敗。任何幫助將非常感激!
注意:儘管最終結果是相同的,但它更習慣於以`[controller doMagic]`的方式調用您的方法。 – 2010-12-07 07:05:06