UIBarButton 忽略“setEnabled:YES”

发布于 2024-08-23 01:30:38 字数 1237 浏览 8 评论 0原文

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

我在 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 上没有任何明显的变化。

有什么想法吗?

多谢!

I ran into a problem. I can't image why that happens, probably you guys can.

I've created a UIBarButtonItem in IB and linked it correctly. A set the property and synthesized it. At the beginning I set the btn disabled (viewWillAppear).
Then I try to add an entry to my mysql db:

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];

In it's "didReceiveData..." I check which value gets returned:

- (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;
    }
...

I already debugged it. The line self.notificationBtnDeactivate.enabled = YES; gets called but without any noticable changes on the UI.

Any Ideas?

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-08-30 01:30:38

我对此有两个想法:

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

I have two ideas for this:

  1. the buttons are not correctly referenced from IB, add some NSAssert and check against nil
  2. you doing your UI changes on the wrong thread. Try to use performSelectorOnMainThread:withObject:waitUntilDone:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文