刷新视图 [英] Refreshing a view

查看:58
本文介绍了刷新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我创建了一个应用程序,在其中一个屏幕中,我有一个呼叫槽屏幕.基本上有18个按钮,范围从09.00-09.30一直到17.30-16.00,每行分成两个按钮.顶部还有两个箭头,允许用户前进最多7天并返回到当前日期.

Okay I have created an application where in one of the screens I have a call slot screen. Basically there are 18 buttons, ranging from 09.00-09.30 all the up up to 17.30-16.00 split up into two buttons per row. There are also two arrows at the top, allowing the user to go forward up to seven days and back to current day.

当用户单击其中一个按钮时,它将弹出并显示警告,指出选择的时间.

When a user clicks one of the buttons, it will pop up with an alert stating the time selected.

现在我想要的是,当用户访问该视图时,任何不可更改的时隙都将具有不同的图像.

Now what I want is, when the user accesses this view, any timeslot that is not available to be changed to have a different image.

我已经创建了这样的按钮

I have created the buttons like this

    for(int i = 0; i <[imageList count]; i++){
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(xPos, yPos, 145, 55)];
    csBut = [[UIButton alloc]init];
    csBut = [UIButton buttonWithType:UIButtonTypeCustom];
    csBut.frame = CGRectMake(0, 0, 145, 55);
    [csBut addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [csBut setImage:[imageList objectAtIndex:i] forState:UIControlStateNormal];
    csBut.tag = (100 + i);
    [myView addSubview:csBut];
    [SV  addSubview:myView];

    if(i % 2 == 0){
        xPos += 160;    
    }else{
        yPos+=60; 
        xPos = 5;
    }

} 

[self emptySlots];

}

现在在底部声明的empty slot方法是一种扫描每个时隙并检查小时是否小于当前小时的方法.如果是,则将图像更改为淡出的按钮图像.代码是

Now the empty slots method declared at the bottom, is a method which scans each timeslot and checks if the hour is less than the current hour. If it is, then image is changed to a the faded out button image. Code is

-(void)emptySlots{

int tmpValue = 100;
int myInteger = 1;
int tmpHour = 9;
int tmpMinute = 0;

for(int i = 0 ; i <18; i++){
    UIButton *validSlot = (UIButton*)[self.view viewWithTag:tmpValue];

    if(i % 2 == 0){

        tmpMinute = (arc4random() % 30);
    }else{

        tmpMinute = (arc4random() % 30) + 30;
        tmpHour+=1;

    }

    [self checkValidSlot:tmpHour :tmpMinute];

    if(tslot){
        NSString* myNewString = [NSString stringWithFormat:@"tb%i.png", myInteger];    
        [validSlot setImage:[UIImage imageNamed:myNewString] forState:UIControlStateSelected];
        [validSlot setSelected:YES]; 
    }else{
        NSString* myNewString = [NSString stringWithFormat:@"fb%i.png", myInteger];    
        [validSlot setImage:[UIImage imageNamed:myNewString] forState:UIControlStateSelected];
        [validSlot setSelected:YES]; 
    }

    tmpValue+=1;
    myInteger+=1;
}

}

空插槽代码尚不完善,尚待解决,但不是我遇到的问题.

The empty slots code is not perfect yet, still few things to fix, but not the issue I am having.

我遇到的问题是,当用户单击向右箭头转到第二天时,它将运行名为fillslots的代码,该代码会在第二天该时隙可用时使用正常按钮自动重新填充时隙.问题是它不会立即刷新.与用户单击后退箭头以返回到当前日期并运行空槽方法一样,我必须再次单击箭头才能刷新.

The problem I am having is when the users click the right arrow, to go to the next day, it runs code called fillslots, which automatically refills in the slots with the normal buttons as the next day the timeslots will be available. The problem is it does not refresh straight away. Same with when the users click back arrow to go back to the current day and runs the empty slots method, I have to click the arrow again before it refreshes.

如何做到这一点,当用户单击箭头时,它会自动刷新视图,因此我不必再次单击箭头,因为它相当令人沮丧,我无法弄清楚它:@

How do I make it so when the user clicks the arrow, it automatically refreshes the view so I don't have to click the arrow again as its rather frustrating and I can't figure it out :@

在此先感谢您的帮助.希望我足够清楚

Thanks in advance for any help. Hope I was clear enough

推荐答案

我设法弄清楚了.我用线程更新了调用槽,效果很好:D

I managed to figure it out. I used threads to update the callslots and it worked perfectly :D

这篇关于刷新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆