【问题标题】:Push to another view controller taking too much time in iphone推送到另一个视图控制器在 iphone 中花费了太多时间
【发布时间】:2013-12-23 19:46:24
【问题描述】:

我有一个应用程序,我最初在其中打开一个来自网络服务的图像网格。

我正在使用 danieltull 的 DTGridView。

这些图片来自不同的类别,如自然、艺术、绘画等。

当应用程序启动时,网格包含所有类别的图像。

主屏幕上有一个类别按钮,单击哪个用户将被推送到另一个视图,其中提到了不同的类别,如自然、艺术、绘画等。

如果用户单击任何类别,他将再次被引导至图像网格,但将仅包含来自该选定类别的图像。

问题在于,当用户单击任何类别时,导航到网格视图需要花费太多时间。

当用户点击任何类别时,我正在从 web 服务获取数据。

我想在用户单击类别后立即将其导航到 Gridview,然后想显示自定义 Spinner。

在选择类别时,我正在执行以下代码并调用 gridview 的方法。

 if ([self isPad])
    {
         vc = [[ViewController alloc]initWithNibName:@"ViewController_iPad" bundle:nil];
    }
 [self.navigationController pushViewController:vc animated:NO];
[vc getCategoryNames];

请帮帮我。

** 已编辑 **

- (NSInteger)numberOfRowsInGridView:(DTGridView *)gridView
{
    if (countimages % 4 == 0)
    {
        return countimages/4;
    }
    else
    {

        return countimages/4 + 1;

    }

}

- (NSInteger)numberOfColumnsInGridView:(DTGridView *)gridView forRowWithIndex:(NSInteger)index
{
    return 4;
}

- (CGFloat)gridView:(DTGridView *)gridView1 heightForRow:(NSInteger)rowIndex
{
    return gridView1.frame.size.height / 3;
    // return 300;
   // NSLog(@"%f",gridView1.frame.size.height/3);

}

- (CGFloat)gridView:(DTGridView *)gridView1 widthForCellAtRow:(NSInteger)rowIndex column:(NSInteger)columnIndex
{
    return gridView1.frame.size.width / 4;
    //return 300;
  //  NSLog(@"%f",gridView1.frame.size.width/4);
}

- (DTGridViewCell *)gridView:(DTGridView *)gv viewForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {

    DTGridViewCell *cell = [gv dequeueReusableCellWithIdentifier:@"cell"];

    if (!cell) {
        cell = [[DTGridViewCell alloc] initWithReuseIdentifier:@"cell"];
  UIView* v=[[UIView alloc]init];
    v.frame=CGRectMake(0, 0, gridView.frame.size.width / 4, gridView.frame.size.height / 3);
    [cell addSubview:v];

    imgeIndex = 0;
    imgeIndex = (rowIndex * 4) + columnIndex;

    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, gridView.frame.size.width / 4, gridView.frame.size.height / 3)];
    [btn setTag:imgeIndex+1];
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    btn.contentMode = UIViewContentModeScaleAspectFit;
 if ([arr_imgurl count] <= imgeIndex)
        {
            btn.imageView.image=[UIImage imageNamed:@"logo_256.png"];
            return cell;
        }
        else
        {
            //NSLog(@"arr %d",[arr_imgurl count]);
            // NSLog(@"imgindex %d",imgeIndex);
            // NSLog(@"array %@",arr_imgurl);
            NSURL *url = [NSURL URLWithString:[arr_imgurl objectAtIndex:imgeIndex]];
            //NSLog(@"%@",url);
            [btn setImageWithURL:url placeholderImage:[UIImage imageNamed:@"logo_256.png"]];


        }
 btn.titleLabel.textColor = [UIColor whiteColor];

    [v addSubview:btn];
    [database close];

    return cell;
}

这里 arr_imgurl 包含来自 web 服务的图像路径。

【问题讨论】:

  • 您点击按钮时的邮政编码和图像大小?
  • 我为此只使用了一个简单的 self.navigationcontroller pushview,并通过从这个 categoryview 制作该视图的对象来调用 gridview 的方法
  • 这可能是因为加载图像需要时间。你在使用后台线程吗?
  • 放一些没有代码的代码,我无法理解问题发生在哪里
  • 是的,加载图像需要太多时间。不,我没有使用任何线程。

标签: ios iphone objective-c gridview


【解决方案1】:

在导航时从不调用 Web 服务(原因:它会一直保持导航直到收到完整的信息,我们始终无法确定服务器速度)。所以更好地导航,然后在线程中调用服务,同时显示带有活动指示器的屏幕,这样用户会认为应用程序正在加载图像。(确保图像加载延迟,因为用户没有耐心等到所有图像都加载完毕) .如果您需要此示例,我将对其进行编码并提供给您。

【讨论】:

  • 欢迎@Manthan,我们在这里互相帮助
【解决方案2】:

大多数情况是在新视图控制器中加载网格的所有数据需要时间。
这种“不正确”的数据加载有很多不同的场景。

可能是web服务在主线程中同步加载。
它可能是在主线程中同步加载图像(在网格委托中)。
等等。

请发布一些网格数据初始化和网格委托的代码,以便更好地理解确切的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 2017-04-24
    相关资源
    最近更新 更多