简体   繁体   English

滚动UIPickerView,UITableView ios8,ios9时UI被冻结

[英]UI getting freezed while scrolling UIPickerView, UITableView ios8, ios9

I am having a view which contains a pickerView and a TextView. 我有一个视图,其中包含pickerView和TextView。
The scrolling is getting stuck more and more when i present my view. 当我展示我的观点时,滚动变得越来越困难。
After coming 4-5 times to the view, it stuck more and more and finally UI get completely freeze while scrolling the UIPickerView. 在进入视图4-5次之后,它越来越粘住,最终在滚动UIPickerView时UI完全冻结。 The PickerView is haveing 4 components out of which 3 has around 50 value. PickerView有4个组件,其中3个组件的值约为50。

Please check my PickerView code below: 请检查以下我的PickerView代码:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 4;
}

// The number of rows of data
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:    (NSInteger)component
{
    return [[_pickerData objectAtIndex:component] count];
}


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:   (NSInteger)component
{
    switch (component){
       case 0:
           return 150.0;
       case 1:
           return 50.0f;
       case 2:
           return 20.0f;
       case 3:
           return 50.0f;
   }
   return 0;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row    forComponent:(NSInteger)component reusingView:(UIView *)view{
   UILabel* tView = (UILabel*)view;
   if (!tView){
       tView = [[UILabel alloc] init];
       tView.font=[UIFont fontWithName:@"ArialNarrow" size:22];
       tView.textAlignment=NSTextAlignmentCenter;
       tView.text=_pickerData[component][row];
       // Setup label properties - frame, font, colors etc



      }

       return tView;
   }

Please help me. 请帮我。

if you want to show only text in pickerView then i recommended you use this method . 如果您只想在pickerView显示text ,那么我建议您使用此方法。

- (NSAttributedString*) pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {

    NSAttributedString *str =  [[NSAttributedString alloc] initWithString:_pickerData[component][row] attributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"ArialNarrow" size: 22], NSFontAttributeName, nil]];
    return str;
}

instead of of using 而不是使用

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row    forComponent:(NSInteger)component reusingView:(UIView *)view

may be lable alloc many times. 可能多次lable

hope it help you . 希望对你有帮助。

Thanks for the help Garry. 感谢您的帮助Garry。

I have solved the issue. 我已经解决了这个问题。 The issue was with the thread. 问题出在线程上。 I found the issue by pausing the app whenever the app freezes. 每当应用程序冻结时,我都会通过暂停应用程序来发现问题。 On the left side, we can see the running thread. 在左侧,我们可以看到正在运行的线程。 From there I caught the thread called. 从那里,我抓到了被称为线程。 It was disturbing the main thread and that is why app was getting freeze. 它打扰了主线程,这就是为什么应用程序被冻结的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM