gpt4 book ai didi

iphone - UIButton setTitle forState 不起作用

转载 作者:行者123 更新时间:2023-12-03 18:20:46 26 4
gpt4 key购买 nike

当从上一个 View 中按下“下一步”按钮时,我试图在新 View 上设置 UIButton 的文本。我已经正确设置了 IBOutlet,并且我已经到处寻找答案,但它根本不起作用。

这是我正在尝试做的事情的示例:

- (IBAction)computeQuiz:(id)sender
{
[fiveFootUniversalResults setTitle:@"Test" forState:UIControlStateNormal];
}

- (IBAction)jumpT10ResultsView:(id)sender
{
NSString *nibFileToLoad = @"JumpT10Results";

UIDevice *device = [UIDevice currentDevice];

if([device userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
nibFileToLoad = [nibFileToLoad stringByAppendingString:@"-iPad"];
}

JumpmasterPathfinderViewController *nextView = [[JumpmasterPathfinderViewController alloc] initWithNibName:nibFileToLoad bundle:nil];

// Modal view controller
nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nextView animated:YES];

[nextView release];

[scrollView setContentSize:CGSizeMake(imageViewWidth, imageViewHeight + 44.0)];
}

这些操作都连接到上一个 View 上的按钮。 View 加载正常,一切正常,唯一的问题是按钮上的文本不会改变。我 100% 确定我已正确设置 IBOutlets,我只是不知道我做错了什么。有什么想法吗?

最佳答案

它不起作用,因为 IB 设置了 attributedTitle 而不是 title

试试这个:

NSAttributedString *attributedTitle = [self.myButton attributedTitleForState:UIControlStateNormal];
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithAttributedString:attributedTitle];
[mas.mutableString setString:@"New Text"];

[self.myButton setAttributedTitle:mas forState:UIControlStateNormal];

或者,另一种选择:

[self.myButton setAttributedTitle:nil forState:UIControlStateNormal];
[self.myButton setTitle:@"New Text" forState:UIControlStateNormal];

(第二个选项不会保留您的格式。)

关于iphone - UIButton setTitle forState 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7986090/

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