在ios中转换拆分字符串
问题描述:
我在我的板球计分板应用程序中有三个文本字段。在ios中转换拆分字符串
如果我点击的每一个动作按钮,我想每一个由0.1,0.2,0.3,0.4,0.5
每个接管数0.5后,它应该是1.0,那么就应该继续为1.1,1.2。 ...... 1.5,2.1,2.2,2.3,2.4,2.5,3.1 ......
对于每一个动作按钮,请帮助我,这
IBOutlet UITextField *score;
IBOutlet UITextField *wickets;
IBOutlet UITextField *overs;
-(IBAction)dot:(id)sender;
-(IBAction)extras:(id)sender;
这是我曾尝试:
-(IBAction)dot:(id)sender
{
if(txtOvers.Text.split(“.”)[1]! = 5)
txtOver.text = txtOver.Text + .1;
else
txtOver.text = 0.5;
}
答
@property (nonatomic, strong) IBOutlet UITextField *txtOver;\
- (void)viewDidLoad
{
[super viewDidLoad];
self.txtOver.text = @"0.1";
}
-(IBAction)dot:(id)sender
{
NSArray *textSplitCollection = [self.txtOver.text componentsSeparatedByString:@"."];
int lastPrecisionValue = ([textSplitCollection count] > 1)?[[textSplitCollection objectAtIndex:1] intValue]:0;
if (5 == lastPrecisionValue)
{
self.txtOver.text = [NSString stringWithFormat:@"%.01f", [self.txtOver.text floatValue] + 0.5];
}
else
{
self.txtOver.text = [NSString stringWithFormat:@"%.01f", [self.txtOver.text floatValue] + 0.1];
}
}
+0
感谢它对我的工作 – 2014-12-03 05:57:33
请告诉我们您尝试过的。 – Vino 2014-12-03 04:51:30
- (IBAction为)点:(ID)发送方{ 如果(txtOvers.Text.split()[1] = 5 txtOver.text = txtOver.Text + 0.1; 否则 txtOver.text = O“”! .5; – 2014-12-03 04:54:56