gpt4 book ai didi

iphone - UIBarButton忽略 "setEnabled:YES"

转载 作者:行者123 更新时间:2023-12-03 20:11:32 27 4
gpt4 key购买 nike

我遇到了一个问题。我无法想象为什么会发生这种情况,也许你们可以。

我已经在 IB 中创建了一个 UIBarButtonItem 并正确链接了它。 A设置属性并合成它。一开始我将 btn 设置为禁用(viewWillAppear)。然后我尝试向我的 mysql 数据库添加一个条目:

NSString *URLStr = [NSString stringWithFormat:@"http://www.justfortestingandsoon.com/example.php?entry=%@", myEntry];
URLStr = [URLStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@"URLStr: %@",URLStr);
NSURL *addURL = [NSURL URLWithString:URLStr];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:addURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
urlConnectionSet = [NSURLConnection connectionWithRequest:urlRequest delegate:self];

在“didReceiveData...”中,我检查返回哪个值:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSData *myData;
myData = data;
NSString *testString = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
NSLog(@"receivedData: %@", testString);
if ([testString isEqualToString:@"ENABLED"]) {
self.notificationBtnDeactivate.enabled = YES;
}
...

我已经调试过了。该行 self.notificationBtnDeactivate.enabled = YES;被调用,但 UI 上没有任何明显的变化。

有什么想法吗?

非常感谢!

最佳答案

对此我有两个想法:

  1. 按钮未从 IB 正确引用,添加一些 NSAssert 并检查 nil
  2. 您在错误的线程上进行 UI 更改。尝试使用performSelectorOnMainThread:withObject:waitUntilDone:

关于iphone - UIBarButton忽略 "setEnabled:YES",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2320263/

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