// btnstartgame.enabled = yes但不应该启用,我不知道为什么,请帮忙。
// PS。这段代码为2个标签提供了一些保存的字符串,然后检查它们是否相同,但由于某些原因它们永远不会相同。 (他们= lblTeamOne和lblTeamTwo)
@synthesize lblTeamOne;
@synthesize lblTeamTwo;
@synthesize sliderTeamOneOutlet;
@synthesize sliderTeamTwoOutlet;
@synthesize btnStartGame;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
-(void)loadTeams:(NSString*)location:(UILabel*)lblname
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:location];
lblname.text = loadstring;
}
-(void)sliderdisplay:(UISlider *)sliderOutlet :(UILabel *)lblName
{
if(0 < sliderOutlet.value && 1 >= sliderOutlet.value)
{
[self loadTeams:@"save1" :lblName];
}
if(1 < sliderOutlet.value && 2 >= sliderOutlet.value)
{
[self loadTeams:@"save2" :lblName];
}
if(2 < sliderOutlet.value && 3 >= sliderOutlet.value)
{
[self loadTeams:@"save3" :lblName];
}
if(3 < sliderOutlet.value && 4 >= sliderOutlet.value)
{
[self loadTeams:@"save4" :lblName];
}
if(4 < sliderOutlet.value && 5 >= sliderOutlet.value)
{
[self loadTeams:@"save5" :lblName];
}
if(5 < sliderOutlet.value && 6 >= sliderOutlet.value)
{
[self loadTeams:@"save6" :lblName];
}
if(6 < sliderOutlet.value && 7 >= sliderOutlet.value)
{
[self loadTeams:@"save7" :lblName];
}
if(7 < sliderOutlet.value && 8 >= sliderOutlet.value)
{
[self loadTeams:@"save8" :lblName];
}
}
-(void)loadMaximum
{
int teamAmount = [[[NSUserDefaults standardUserDefaults] objectForKey:@"teamAmount"] intValue];
NSNumber *yourNumber = [NSNumber numberWithInt:teamAmount];
float sliderMaximumDigital = [yourNumber floatValue];
[sliderTeamOneOutlet setMaximumValue:sliderMaximumDigital];
[sliderTeamTwoOutlet setMaximumValue:sliderMaximumDigital];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadMaximum];
[self loadTeams:@"save1" :lblTeamOne];
[self loadTeams:@"save1" :lblTeamTwo];
if(lblTeamOne == lblTeamTwo)
{
btnStartGame.enabled = NO;
}
if(lblTeamOne.text == lblTeamTwo.text)
{
btnStartGame.enabled = NO;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)sliderTeamOneAction:(id)sender
{
[self sliderdisplay:sliderTeamOneOutlet :lblTeamOne];
}
- (IBAction)sliderTeamTwoAction:(id)sender
{
[self sliderdisplay:sliderTeamTwoOutlet :lblTeamTwo];
}
//提前谢谢你。
答案 0 :(得分:3)
要比较字符串,请执行以下操作:
[string1 isEqualToString:string2]
如果你使用==,你实际上是在比较内存中的位置(通常是不同的)而不是字符串的内容。
答案 1 :(得分:0)
你可以使用这个代码Ben是对的我给你一个链接,你找到了你的解决方案。另一个人面临着问题。所以你也可以在这里找到你的解决方案 -