-1

我试图让 UILabel.text 采用 NSString 自定义函数,但被错误难住了。我仍然是 iOS 的新手,但我的直觉表明它与语法有关。

- (void)viewDidLoad
{
    ...

    //Creating scrollable view
    CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460);
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
    [self.view addSubview:scrollView];

    CGSize scrollViewContentSize = CGSizeMake(320, 800);
    [scrollView setContentSize:scrollViewContentSize];

    //Inserting Title
    UILabel *title = [[UILabel alloc]init];
    [title setFrame:CGRectMake(0, 0, 300, 40)];
    title.backgroundColor = [UIColor clearColor];
    title.text = self.setQuestion;<-error
    [scrollView addSubview:title];
    [title release];
}
- (void) setQuestion{
    NSString *qn = [NSString stringWithFormat:@"What do you get with%@", 5];

}

提前谢谢...

4

1 回答 1

2

title.text = [self setQuestion];

但是setQuestion编码不正确。应该:

- (NSString*) setQuestion{
    return [NSString stringWithFormat:@"What do you get with %d", 5];
}

并且不要忘记setQuestion在您的 .h 文件中包含原型。

(好吧,实际上,格式字符串也编码不正确。应该是“What do you get with %d”。)

于 2012-04-20T17:06:00.000 回答