作者tentenlee (天天)
看板MacDev
标题Re: [问题]两个coding上的小问题
时间Sun Oct 12 20:16:35 2014
1.
个人很讨厌一堆if一层一层的下去,所以大多都这样做
NSArray *buttonsArray = [NSArray arrayWithObjects:radiobutton1,
radiobutton2,
radiobutton3,
radiobutton4,
radiobutton5];
bool noButtonIsSelected = NO;
for (UIButton *tempButton in buttonsArray){
if(tempButton.isSelected == YES){
noButtonIsSelected = YES;
break;
}
}
if (noButtonIsSelected){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TITLE"
message:@"message"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NextPage.hidden = YES;
}else{
NextPage.hidden = NO
}
2.
这问题应该很简单...
就是你干嘛宣告 float 但是里面塞的值是int呀~
看你的label.text有没有可能是小数点的
有就把他转成floatValue 不然就一律转int吧
※ 引述《ljuyentintho (小刘)》之铭言:
: 抱歉我又来发问了(汗)
: 1.
: 我要设定一个防呆
: 防呆的内容是当每一个radio button都没有按到时
: 会跳出警告视窗而且next page这个按钮就不会出现(预设值就是hidden)
: 程式码如下:
: if ([radiobutton1 isSelected]==NO) {
: if ([radiobutton2 isSelected]==NO) {
: if ([radiobutton3 isSelected]==NO) {
: if ([radiobutton4 isSelected]==NO) {
: if ([radiobutton5 isSelected]==NO) {
: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You do not choose radio button,it's nessary" message:@"Please choose one at least" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
: [alert show];
: NextPage.hidden=YES;
: }
: }
: }
: }
: }
: NextPage.hidden=NO;
: 每次一按下去虽然会跳出警告视窗
: 可是next page的按钮也会出现
: 这样就跟没有防呆一样了(next page是用seguse)
: 该怎麽解决呢?
: 2.
: 我需要读label里面的值
: 然後丢到演算法去对应出一个值
: int PostureScoreA;
: float LocateUpperArm=[[LocateUpperArmInWristTwist text]intValue];
: float LocateLowerArm=[[LocateLowerArmInWristTwist text]intValue];
: float LocateWrist=[[LocateWristInWristTwist text]intValue];
: float WristTwist=[[WristTwistResult text]intValue];
: //范例演算法
: if (LocateUpperArm==1) {
: if (LocateLowerArm==1) {
: if (LocateWrist==1) {
: if (WristTwist==1) {
: PostureScoreA=1;
: }
: }
: }
: } //(1,1,1,1)
: PostureA.text = [NSString stringWithFormat:@"%.f",(PostureScoreA)];
: 可是每次执行都会断在LocateUpperArm这一行
: 请问原因在哪里?
: 以上两个问题
: 谢谢大家~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.132.180.49
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1413116197.A.4C7.html
1F:推 darktt: 第一项其实也可以这样子做 10/12 21:58
2F:→ darktt: bool buttonSelect = No; 10/12 21:59
3F:→ darktt: buttonSelect |= radiobutton1.select 10/12 21:59
4F:→ darktt: buttonSelect |= radiobutton2.select 10/12 22:00
5F:→ darktt: 这样子下去,最後再判断buttonSelect是不是Yes就好了 10/12 22:00
可以呀~ 只是我习惯用这方法因为你在for里面可以判定很多东西
所以就习惯了~
※ 编辑: tentenlee (220.132.180.49), 10/12/2014 22:37:22
6F:推 howdiun: 把它模组化的话就只能用回圈了 10/13 09:23