gpt4 book ai didi

ios - 在 UIButton 中添加 UIActivityIndi​​catorView

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:04:22 24 4
gpt4 key购买 nike

我在这里阅读了关于在 UIButton 中添加 UIActivtyIndi​​catorView 的各种帖子,但到目前为止,没有一篇对我有帮助。

我有一个带有单元格的表格 View ,每个单元格中都有按钮,上面写着“开始”。当用户单击一个按钮时,我希望该按钮显示一个 UIActivtyIndi​​catorView,直到完成所有背景工作。这里我使用一些解析方法在后台保存用户信息。

我有一个方法

- (void)going:(UIButton *)button {

NSLog(@"going button pressed");

//Added this code
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithFrame:button.bounds];
[button addSubview:activity];
[activity startAnimating];

if ([button.titleLabel.text isEqualToString:@"Go"]) { // Select
....
// Just code changing user info

[PFObject saveAllInBackground:save block:^(BOOL success, NSError *error) {

if (success) {

//Do more stuff so save user info in background
}
}];
}
else { // Deselect

//More stuff
if (success) {

//Toggle button
[defaults setObject:@"" forKey:@"currentBarID"];
[defaults synchronize];
selectedGoingToButton = nil;
[self deselectGoingButton:button];
[self reloadData];
}
}];
}
}
- (void)selectGoingButton:(UIButton *)button {



NSLog(@"GoingButtonselected");
[button setTitle:@"Going" forState:UIControlStateNormal];
button.layer.borderColor = neonBlue.CGColor;
[button setNeedsDisplay];
}

如您所见,这两种方法是我将按钮从纯色切换为突出显示颜色的地方,但在按钮突出显示之前,我希望显示 UIActivityIndi​​catorView。

目前它不显示,按钮只是切换颜色而不显示 ActivtyIndi​​cator。

感谢任何帮助。谢谢!

编辑:更改了 UIActivityView 初始行,以便我现在传入 button.bounds 属性。

ActivtyIndi​​catorView 现在正在显示,但现在我的问题是重新加载圆圈显示在“GO”按钮标题下,然后在标题更改时停止。我想要它,以便在显示 ActivityIndi​​cator 时按钮标题消失。有什么建议吗?

最佳答案

- (void)selectGoingButton:(UIButton *)button 
{

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(25, 25, 50, 50)];
activityIndicator.backgroundColor = [UIColor clearColor];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[activityIndicator startAnimating];
[yourview addSubview:activityIndicator];


NSLog(@"GoingButtonselected");
[button setTitle:@"Going" forState:UIControlStateNormal];
button.layer.borderColor = neonBlue.CGColor;
[button setNeedsDisplay];
}







- (void)going:(UIButton *)button
{

NSLog(@"going button pressed");

//Added this code
//UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithFrame:button.bounds];
//[button addSubview:activity];
//[activity startAnimating];

if ([button.titleLabel.text isEqualToString:@"Go"]) { // Select
....
// Just code changing user info

[PFObject saveAllInBackground:save block:^(BOOL success, NSError *error) {

if (success) {

//Do more stuff so save user info in background
}
}];
}
else { // Deselect

//More stuff
if (success) {

//Toggle button
[defaults setObject:@"" forKey:@"currentBarID"];
[defaults synchronize];
selectedGoingToButton = nil;
[self deselectGoingButton:button];
[self reloadData];
}
}];
}

[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}

希望对你有帮助。

关于ios - 在 UIButton 中添加 UIActivityIndi​​catorView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24719290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com