-2

I'm trying to get a UILabel.text to adopt an NSString self defined function but are stumped with the error. I am still a newbie with iOS but my gut feeling says its something to do with syntax.

- (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];

}

Thanx in advance...

Joe Shamuraq
  • 1,245
  • 3
  • 18
  • 32

1 Answers1

2

title.text = [self setQuestion];

But setQuestion is improperly coded. Should be:

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

And don't forget to include the prototype of setQuestion in your .h file.

(Well, actually, the format string is improperly coded too. Should be "What do you get with %d".)

Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • 1
    Incidentally, this method isn't actually setting anything, so a better name would be something like `textForQuestion`. – Chuck Apr 20 '12 at 17:31
  • The reason is because the 'question' part is just the tip of the ice berg. I have to also provide the choices that comes with the question. So i dun think i can use the (NSString *). It has to be NSArray... – Joe Shamuraq Apr 21 '12 at 17:30
  • @TeamStar -- Then you can't assign the result directly to the `text` attribute, but must index the array somehow, or concatenate the values into a single string. – Hot Licks Apr 22 '12 at 00:26
  • @HotLicks - Precisely... I managed to solve it using NSArray... :) – Joe Shamuraq Apr 26 '12 at 12:47