我们知道我们需要在块内部使用弱引用来打破保留周期,如下所示:
__weak id weakSelf = self;
[self doSomethingWithABlock:^() {
[weakSelf doAnotherThing];
}]
Run Code Online (Sandbox Code Playgroud)
但弱引用不能打破由a引起的保留周期NSTimer
.
__weak id weakSelf = self;
timer = [NSTimer scheduledTimerWithTimeInterval:30.0f
target:weakSelf
selector:@selector(tick)
userInfo:nil
repeats:YES]; // No luck
Run Code Online (Sandbox Code Playgroud)
有什么不同?计时器如何仍然保留目标?
这是我的问题,我正在开发一个新闻应用程序,我使用scrollview包装textview来显示新闻的内容.但是我发现当textview很长时,android 4.0的滚动速度非常慢,文本越长,滚动越慢.在Android 2.3设备上,事情的速度和预期一样快.
我不知道这是否真的是系统错误,因为我发现在android项目中报告了类似的问题
这是我的布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@id/lst_news_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/list_background"
android:fadingEdge="none"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="@id/tv_news_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Detail_Title"/>
<TextView
android:id="@id/tv_news_details_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Detail_Category"/>
<TextView
android:id="@id/tv_news_details_created_at"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
style="@style/Detail_Time"/>
<include layout="@layout/detail_horizontal_divideline" />
<ImageView
android:id="@id/img_news_details_image"
style="@style/Detail_Picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/image_contentDescription"/>
<TextView
android:id="@id/tv_news_details_context"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
style="@style/Detail_Content"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dip" />
</LinearLayout>
</ScrollView>
<!-- actionbar shadow -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)