0

如何UIButton在选择时保持自定义突出显示约 5 秒钟,然后重定向到其他视图?在我的代码中,它在选择时不显示任何颜色,而是重定向到其他视图。

这是我的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 CGRect rect=CGRectMake(0+70*j,yy,79,40);
            UIButton *button=[[UIButton alloc] initWithFrame:rect];
            [button setFrame:rect];
            [button setContentMode:UIViewContentModeLeft];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            NSString *settitle=[NSString stringWithFormat:@"%@",item.TimeStart];
            [button setTitle:settitle forState:UIControlStateNormal];
            NSString *tagValue=[NSString stringWithFormat:@"%d%d",indexPath.section+1,i];
            button.tag=[tagValue intValue];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setShowsTouchWhenHighlighted:YES];     
            [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
            [hlcell.contentView addSubview:button];
            [button release];
}

-(IBAction)buttonPressed:(id)sender
{
    [sender setBackgroundColor:[UIColor cyanColor]];
    Login *lgn=[[Login alloc] init];
    [self presentModalViewController:lgn animated:NO];
    [lgn release];
}

我该怎么做 ?

4

3 回答 3

0

您必须设置setShowsTouchWhenHighlighted:yes为 UIButton。

例如:

UIButton *click_btn=[UIButton buttonWithType:UIButtonTypeCustom];
    click_btn.frame=CGRectMake(238,10, 70, 70);
    [click_btn setTag:indexPath.row];
    [click_btn setShowsTouchWhenHighlighted:YES];
    [click_btn addTarget:self action:@selector(sample) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:click_btn];
于 2012-10-19T10:27:08.220 回答
0

我不建议使用 sleep() ,因为这会使所有线程休眠并使应用程序基本上死了 x 秒。

按照上面的说明突出显示按钮,然后使用

[self performSelector:@selector(sample) withObject:self afterDelay:5.0f];


-(void)sample
{
     UIViewController *myNewController = [[UIViewController alloc]init];
    enter code here
    [self presentModalViewController:myNewController animated:YES];
}
于 2012-10-19T11:32:51.690 回答
0

您只需在该方法中添加 sleep(5);

例如:

这是用户示例 uibutton 操作方法。

-(无效)样本{

睡眠(5);

sampleclass *classobject=[[sampleclass alloc]init]; [self.navigationController pushViewController:classobject Animation:YES];

}

于 2012-10-19T11:18:45.340 回答