views:

173

answers:

1

Hi, newbie here...I'd like take my input which is an NSString and use NSScanner to identify and act upon the characters typed. I've taken another example i've found and modified it however need more help.

For example:

NSString *yourString = @"Hello"; // For example
NSScanner *scanner = [NSScanner scannerWithString:yourString];

NSCharacterSet *charactersToCount = [NSCharacterSet characterSetWithCharactersInString:@"H"]; // For example
NSString *charactersFromString;

if ([scanner scanCharactersFromSet:charactersToCount intoString:&charactersFromString]) {
 // display H button, the same for E, L, L, or any other A-Z character which will have a button

}

NSInteger characterCount = [charactersFromString length];

I would like the H, E, L, L, O buttons to be displayed if Hello is the string. Any simple way of scanning and displaying the buttons according to what is typed with the NSScanner ?

Thanks,

A: 

It looks like you've already got the code, just add an NSMutableArray and fill it with UIButton instances with the text from the scanner.

To add views on the fly, it would depend on your viewcontroller, but it might be as simple as

[myViewController.view addSubview:myButton];
slf