小编LS_*_*LS_的帖子

"在这个区块中强烈捕捉'自我'可能会导致保留周期"使用可达性

我正在尝试使用Objective-C编辑Reachability块中的变量,这是代码:

- (void)testInternetConnection
{
    internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
    // Internet is reachable
    internetReachableFoo.reachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Connessione ad Internet disponibile");
            checkConnection = YES;
            if(!lastConnectionState)
            {
                lastConnectionState = YES;
                if(doItemsDownload)
                    [self displayChoice];
            }
        });
    };

    // Internet is not reachable
    internetReachableFoo.unreachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Connessione ad Internet non disponibile");
            checkConnection = NO;
            lastConnectionState = NO;
        });
    };

    [internetReachableFoo startNotifier];
}
Run Code Online (Sandbox Code Playgroud)

凡 …

objective-c

1
推荐指数
1
解决办法
1986
查看次数

UIView 框架未在 viewDidAppear 中更新

我正在使用Storyboardautolayout. 在我的中,ViewController我有一个基本结构:一个UIScrollView和一个包含不同标签的 contentView ( UIView)。然后我在viewDidAppearmy 类的方法中添加了不同的元素contentView,然后为了重新计算它的帧大小,我这样做:

- (void)fixContentViewHeight 
{
    _contentView.frame = CGRectMake(_contentView.frame.origin.x, _contentView.frame.origin.y, _contentView.frame.size.width, operators.frame.origin.y + operators.frame.size.height);
     //constraint for contentView height
    _contentViewHeight.constant = operators.frame.origin.y + operators.frame.size.height;
}

- (void)fixScrollViewHeight 
{
    _scrollView.frame = _contentView.frame;
    _scrollView.contentSize = _contentView.frame.size;
}
Run Code Online (Sandbox Code Playgroud)

其中operators是 最后放置的元素contentView,它始终位于框架的底部。我在 中调用这两个方法,viewDidAppear它们使视图可滚动,问题是 的框架contentView没有更新,因此最后一个元素始终不可单击(因为它们放置在视图框架之外)。

我究竟做错了什么?为什么scrollView变得可滚动但contentView保持旧框架?

objective-c uiview ios

1
推荐指数
1
解决办法
3134
查看次数

在AsyncTask Android上显示alertDialog onPostExecute

我有一个asyncTask,我想显示一个方法alertDialog何时onPostExecute被触发.我声明了一个Context变量,我在OnCreate方法中初始化它,如:

mContext = this;
Run Code Online (Sandbox Code Playgroud)

然后为了显示alertDialogonPostExecute方法,我使用了以下代码:

            AlertDialog.Builder goLogin = new AlertDialog.Builder(mContext);
            goLogin.setMessage("test");
            goLogin.setCancelable(false);
            goLogin.setPositiveButton("ok",
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
        AlertDialog alertLogin = goLogin.create();
        alertLogin.show();
Run Code Online (Sandbox Code Playgroud)

但我得到的是以下错误:

07-10 14:42:09.710: E/AndroidRuntime(12963): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
07-10 14:42:09.710: E/AndroidRuntime(12963):    at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:148)
07-10 14:42:09.710: E/AndroidRuntime(12963):    at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:99)
07-10 14:42:09.710: E/AndroidRuntime(12963):    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:154)
07-10 14:42:09.710: E/AndroidRuntime(12963):    at android.app.AlertDialog$Builder.<init>(AlertDialog.java:379)
07-10 14:42:09.710: …
Run Code Online (Sandbox Code Playgroud)

java android

0
推荐指数
1
解决办法
4436
查看次数

需要用百分号Java替换字符串中的空格

我需要用%符号替换字符串中的空格,但我遇到了一些问题,我尝试的是:

imageUrl = imageUrl.replace(' ', "%20");
Run Code Online (Sandbox Code Playgroud)

但它在替换功能中给了我一个错误.

然后:

imageUrl = imageUrl.replace(' ', "%%20");
Run Code Online (Sandbox Code Playgroud)

但它仍然在替换功能中给我一个错误.

我尝试使用unicode符号:

imageUrl = imageUrl.replace(' ', (char) U+0025 + "20");
Run Code Online (Sandbox Code Playgroud)

但它仍然给出错误.

有一个简单的方法吗?

java

0
推荐指数
1
解决办法
427
查看次数

标签 统计

java ×2

objective-c ×2

android ×1

ios ×1

uiview ×1