Re: [问题]两个coding上的小问题

楼主: tentenlee (天天)   2014-10-12 20:16:35
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这一行
: 请问原因在哪里?
: 以上两个问题
: 谢谢大家~
作者: darktt (小朱)   2014-10-12 21:58:00
第一项其实也可以这样子做bool buttonSelect = No;buttonSelect |= radiobutton1.selectbuttonSelect |= radiobutton2.select这样子下去,最后再判断buttonSelect是不是Yes就好了
作者: howdiun (Howdiun)   2014-10-13 09:23:00
把它模组化的话就只能用循环了

Links booklink

Contact Us: admin [ a t ] ucptt.com