Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xcode iphone-快速滚动UITableView单元格以获得rowatinexpath_Xcode - Fatal编程技术网

xcode iphone-快速滚动UITableView单元格以获得rowatinexpath

xcode iphone-快速滚动UITableView单元格以获得rowatinexpath,xcode,Xcode,几乎和我的第一个应用程序一样,只是一个简单的新闻应用程序,但当我把它加载到我的iPhone上时,卷轴似乎有点不稳。有人能看看我的功能,看看我是否做错了什么 我需要右边的图像,这就是为什么我使用自定义单元格 谢谢 需要帮忙吗 #define DATELABEL_TAG 1 #define MAINLABEL_TAG 2 #define PHOTO_TAG 3 - (UITableViewCell *)tableView:(UITableView *)tableView cell

几乎和我的第一个应用程序一样,只是一个简单的新闻应用程序,但当我把它加载到我的iPhone上时,卷轴似乎有点不稳。有人能看看我的功能,看看我是否做错了什么

我需要右边的图像,这就是为什么我使用自定义单元格

谢谢 需要帮忙吗

    #define DATELABEL_TAG 1 #define MAINLABEL_TAG 2 #define PHOTO_TAG 3


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{

static NSString *MainNewsCellIdentifier = @"MainNewsCellIdentifier";


UILabel *mainLabel, *dateLabel;

UIImageView *photo;


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: MainNewsCellIdentifier];


    if (cell == nil) 

{

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier: MainNewsCellIdentifier] autorelease];

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;


dateLabel = [[[UILabel alloc] initWithFrame:CGRectMake(15.0,15.0,170.0,15.0)] autorelease];

dateLabel.tag = DATELABEL_TAG;

dateLabel.font = [UIFont systemFontOfSize:10.0];

dateLabel.textAlignment = UITextAlignmentLeft;

dateLabel.textColor = [UIColor darkGrayColor];

dateLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; //| UIViewAutoresizingFlexibleHeight;

[cell.contentView addSubview:dateLabel]; 


mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(15.0,28.0,170.0,60.0)] autorelease];

mainLabel.tag = MAINLABEL_TAG;

mainLabel.font = [UIFont boldSystemFontOfSize:14.0];

mainLabel.textColor = [UIColor blackColor];

mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

mainLabel.numberOfLines = 0;

//mainLabel.backgroundColor = [UIColor greenColor];

[cell.contentView addSubview:mainLabel];


photo = [[[UIImageView alloc] initWithFrame:CGRectMake(190.0,15.0,85.0,85.0)] autorelease]; 

photo.tag = PHOTO_TAG; 

photo.contentMode = UIViewContentModeScaleAspectFit;//UIViewContentModeScaleAspectFit; //


[cell.contentView addSubview:photo];


    }

else {


dateLabel = (UILabel *)[cell.contentView viewWithTag:DATELABEL_TAG];

mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];

photo = (UIImageView *)[cell.contentView viewWithTag:PHOTO_TAG];

}


NSUInteger row = [indexPath row];

NSDictionary *stream = (NSDictionary *) [dataList objectAtIndex:row];

NSString *title = [stream valueForKey:@"title"];



NSString *titleString = @"";


if( ! [title isKindOfClass:[NSString class]] )

{

titleString  = @"";

}

else 

{

titleString = title;

}


CGSize maximumSize = CGSizeMake(180, 9999);


    UIFont *dateFont = [UIFont fontWithName:@"Helvetica" size:14];

    CGSize dateStringSize = [titleString sizeWithFont:dateFont 

constrainedToSize:maximumSize 

lineBreakMode:mainLabel.lineBreakMode];


    CGRect dateFrame = CGRectMake(15.0, 28.0, 170.0, dateStringSize.height);

    mainLabel.frame = dateFrame;


mainLabel.text = titleString;

dateLabel.text = [stream valueForKey:@"created"];


NSString *i = [NSString stringWithFormat:@"http://www.website.co.uk/images/%@", [stream valueForKey:@"image"]];

NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:i]];

UIImage *newsImage = [[UIImage alloc] initWithData:imageURL];


photo.image = newsImage; 

[imageURL release];

[newsImage release];


    return cell;

}
问题是:

NSString *i = [NSString stringWithFormat:@"http://www.website.co.uk/images/%@", [stream valueForKey:@"image"]];

NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:i]];

UIImage *newsImage = [[UIImage alloc] initWithData:imageURL];
在这里,您可以有效地说,一旦需要显示单元格,就必须获取并呈现图像。这将花费一些时间-对于良好的用户体验来说太多了

您应该在呈现表视图之前或同时获取图像,并将其缓存(例如,在数组中)。或者您必须异步处理事情,这意味着您在后台进行加载,而不是等待
返回单元格直到图像实际下载。这将有点难以纠正。

问题在于:

NSString *i = [NSString stringWithFormat:@"http://www.website.co.uk/images/%@", [stream valueForKey:@"image"]];

NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:i]];

UIImage *newsImage = [[UIImage alloc] initWithData:imageURL];
在这里,您可以有效地说,一旦需要显示单元格,就必须获取并呈现图像。这将花费一些时间-对于良好的用户体验来说太多了


您应该在呈现表视图之前或同时获取图像,并将其缓存(例如,在数组中)。或者您必须异步处理事情,这意味着您在后台进行加载,而不是等待
返回单元格直到图像实际下载。这将是一个有点难以正确。即使你异步下载图像,你仍然会有一个不稳定的滚动

为什么??这是懒惰的图像解压缩。ios在屏幕上显示时执行解压缩。您必须在后台线程中手动解压缩图像

解压缩不仅仅意味着实例化UIImage对象。这可能有点复杂。最好的解决方案是下载SDWebImage并使用附带的图像解压缩程序。SDWebImage将异步下载并为您执行解压缩


要了解有关此问题的更多信息,请参阅:

即使异步下载图像,也会出现不稳定的滚动

为什么??这是懒惰的图像解压缩。ios在屏幕上显示时执行解压缩。您必须在后台线程中手动解压缩图像

解压缩不仅仅意味着实例化UIImage对象。这可能有点复杂。最好的解决方案是下载SDWebImage并使用附带的图像解压缩程序。SDWebImage将异步下载并为您执行解压缩

要了解有关此问题的更多信息,请参阅: