我是IOS新手,我正在做简单的程序这一个是一个hang子手游戏。 我想从plist文件中选取一个随机字符串(已完成)。 我现在想比较用户输入文本(来自文本字段)并将其与我们从plist中随机选取的字符串进行比较。有没有反正我可以比较一个字符串(这是一个词)和一个字母,这是由用户输入和接收输出作为BOOL
这是我的MainViewController.m代码,因为它是一个实用程序。目前仅使用MainView。
#import "MainViewController.h"
#import "WordListLoad.h"
@interface MainViewController()
@end
@implementation MainViewController
@synthesize textField=_textField;
@synthesize button=_button;
@synthesize correct=_correct;
@synthesize UsedLetters=_UsedLetters;
@synthesize newgame=_newgame;
- (IBAction)newg:(id)sender
{
[self start];
}
- (void)start
{
NSMutableArray *swords = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"swords" ofType:@"plist"]];
NSLog(@"%@", swords);
NSInteger randomIndex = arc4random() % [swords count];
NSString *randomString = [swords objectAtIndex:randomIndex];
NSLog(@"%@", randomString);
}
这就是我想实现的检查 我试图characterAtIndex,我似乎无法得到它的努力放在编码字符串中让沿着使用for语句系统检查串。
- (void)check: (NSString *) randomString;
{
//NSLogs to check if the values are being sent
NSLog(@"2 %@", self.textField.text);
}
- (IBAction)go:(id)sender
{
[self.textField resignFirstResponder];
NSLog(@"1 %@", self.textField.text);
[self check:(NSString *) self.textField];
_textField.text = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self start];
}
欢迎堆栈溢出的文档!让你的问题得到更快回答的一种方法是提供你有的代码,并在你不懂如何编写的部分写一个简短的评论。祝你好运! – dasblinkenlight
@dasblinkenlight谢谢,我会做。 – HairySocks