こんにちは私はwebservicesから画像を取得していて、テーブルビューでこれらの画像を読み込んでいますが、スクロールを続けるとメモリ警告level1、level2を受け取り、アプリケーションはステータス0それはシミュレータにないデバイスでのみ起こります。 私のコードは私が私を助けてください置いています。私は間違いをしています受信したメモリ警告。レベル= 2、プログラム受信信号: "0"
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *infoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -4, 62, 30)];
[infoButton setBackgroundImage:[UIImage imageNamed: @"back.png"] forState:UIControlStateNormal];
[infoButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarButtomItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
self.navigationItem.leftBarButtonItem = customBarButtomItem;
[customBarButtomItem release];
[infoButton release];
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 62, 30)];
[homeButton setBackgroundImage:[UIImage imageNamed: @"home.png"] forState:UIControlStateNormal];
[homeButton.titleLabel setFont:[UIFont systemFontOfSize:11]];
//[homeButton setTitle:@"UPLOAD" forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtom = [[UIBarButtonItem alloc] initWithCustomView:homeButton];
self.navigationItem.rightBarButtonItem = rightBarButtom;
[rightBarButtom release];
[homeButton release];
sellerTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 416) style:UITableViewStylePlain];
sellerTableView.delegate=self;
sellerTableView.dataSource=self;
sellerTableView.backgroundColor=[UIColor clearColor];
sellerTableView.scrollEnabled=YES;
//table.separatorColor=[UIColor grayColor];
//table.separatorColor=[UIColor whiteColor];
//[[table layer]setRoundingMode:NSNumberFormatterRoundDown];
[[sellerTableView layer]setBorderColor:[[UIColor darkGrayColor]CGColor]];
[[sellerTableView layer]setBorderWidth:2];
//[[productTable layer]setCornerRadius:10.3F];
[self.view addSubview:sellerTableView];
appDel = (SnapItAppAppDelegate*)[[UIApplication sharedApplication] delegate];
}
-(void)viewWillAppear:(BOOL)animated
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
[[SnapItParsing sharedInstance]assignSender:self];
[[SnapItParsing sharedInstance]startParsingForShowProducts:appDel.userIdString];
[sellerTableView reloadData];
}
-(void)showProducts:(NSMutableArray*)proArray
{
if (spinner) {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
spinner = nil;
}
if ([[[proArray objectAtIndex:1]objectForKey:@"Success"]isEqualToString:@"True"]) {
//[self.navigationController popViewControllerAnimated:YES];
//self.view.alpha=.12;
if (productInfoArray) {
[productInfoArray release];
}
productInfoArray=[[NSMutableArray alloc]init];
for (int i=2; i<[proArray count]; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[productInfoArray addObject:[proArray objectAtIndex:i]];
NSLog(@"data fetch array is====> /n%@",productInfoArray);
[pool release];
}
}
}
#pragma mark (tableview methods)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [resultarray count];
return [productInfoArray count];
}
-(void)loadImagesInBackground:(NSNumber *)index{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *frame = [[productInfoArray objectAtIndex:[index intValue]] retain];
//NSLog(@"frame value ==>%@",[[frame objectForKey:@"Image"]length]);
NSString *frameImagePath = [NSString stringWithFormat:@"http://apple.com/snapit/products/%@",[frame objectForKey:@"Image"]];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:frameImagePath]];
NSLog(@"FRAME IMAGE%d",[[frame valueForKey:@"Image" ]length]);
if([[frame valueForKey:@"Image"] length] == 0){
NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[frame setObject:image forKey:@"friendImage"];
[imagePath release];
//[image release];
}
else {
//NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:frameImagePath]];
NSLog(@"image data length ==>%d",[imageData length]);
if([imageData length] == 0){
NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[frame setObject:image forKey:@"friendImage"];
[imagePath release];
//[image release];
}
else {
//UIImage *image = [[UIImage alloc] initWithData:imageData];
UIImage *image = [UIImage imageWithData:imageData];
[frame setObject:image forKey:@"friendImage"];
//[image release];
}
}
[frame release];
frame = nil;
[self performSelectorOnMainThread:@selector(reloadTable:) withObject:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[index intValue] inSection:0]] waitUntilDone:NO];
[pool release];
}
-(void)reloadTable:(NSArray *)array{
NSLog(@"array ==>%@",array);
[sellerTableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celltype];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor=[UIColor clearColor];
//cell.textLabel.text=[[resultarray objectAtIndex:indexPath.row] valueForKey:@"Service"];
/*UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView =
[[[UIImageView alloc]
initWithImage:indicatorImage]
autorelease];*/
/*NSThread *thread=[[NSThread alloc]initWithTarget:self selector:@selector() object:nil];
[thread setStackSize:44];
[thread start];*/
cell.backgroundView=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell.png"]]autorelease];
// [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back.png"]] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake(19, 15, 75, 68)];
imageView.contentMode = UIViewContentModeScaleToFill;
// @synchronized(self)
//{
NSMutableDictionary *dict = [productInfoArray objectAtIndex:indexPath.row];
if([dict objectForKey:@"friendImage"] == nil){
imageView.backgroundColor = [UIColor clearColor];
if ([dict objectForKey:@"isThreadLaunched"] == nil) {
[NSThread detachNewThreadSelector:@selector(loadImagesInBackground:) toTarget:self withObject:[NSNumber numberWithInt:indexPath.row]];
[dict setObject:@"Yes" forKey:@"isThreadLaunched"];
}
}else {
imageView.image =[dict objectForKey:@"friendImage"];
}
//NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
//imageView.layer.cornerRadius = 20.0;//vk
//imageView.image=[UIImage imageWithContentsOfFile:imagePath];
//imageView.layer.masksToBounds = YES;
//imageView.layer.borderColor = [UIColor darkGrayColor].CGColor;
//imageView.layer.borderWidth = 1.0;//vk
//imageView.layer.cornerRadius=7.2f;
[cell.contentView addSubview:imageView];
//[imagePath release];
[imageView release];
imageView = nil;
//}
UILabel *productCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 7, 60,20)];
productCodeLabel.textColor = [UIColor whiteColor];
productCodeLabel.backgroundColor=[UIColor clearColor];
productCodeLabel.text=[NSString stringWithFormat:@"%@",@"Code"];
[cell.contentView addSubview:productCodeLabel];
[productCodeLabel release];
UILabel *CodeValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 7, 140,20)];
CodeValueLabel.textColor = [UIColor whiteColor];
CodeValueLabel.backgroundColor=[UIColor clearColor];
CodeValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"ID"]];
[cell.contentView addSubview:CodeValueLabel];
[CodeValueLabel release];
UILabel *productNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 35, 60,20)];
productNameLabel.textColor = [UIColor whiteColor];
productNameLabel.backgroundColor=[UIColor clearColor];
productNameLabel.text=[NSString stringWithFormat:@"%@",@"Name"];
[cell.contentView addSubview:productNameLabel];
[productNameLabel release];
UILabel *NameValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 35, 140,20)];
NameValueLabel.textColor = [UIColor whiteColor];
NameValueLabel.backgroundColor=[UIColor clearColor];
NameValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"Title"]];
[cell.contentView addSubview:NameValueLabel];
[NameValueLabel release];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 68, 60,20)];
dateLabel.textColor = [UIColor whiteColor];
dateLabel.backgroundColor=[UIColor clearColor];
dateLabel.text=[NSString stringWithFormat:@"%@",@"Date"];
[cell.contentView addSubview:dateLabel];
[dateLabel release];
UILabel *dateValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 68, 140,20)];
dateValueLabel.textColor = [UIColor whiteColor];
dateValueLabel.backgroundColor=[UIColor clearColor];
dateValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"PostedDate"]];
dateValueLabel.font=[UIFont systemFontOfSize:14];
dateValueLabel.numberOfLines=3;
dateValueLabel.adjustsFontSizeToFitWidth=YES;
[dateValueLabel setLineBreakMode:UILineBreakModeCharacterWrap];
[cell.contentView addSubview:dateValueLabel];
[dateValueLabel release];
}
ください-2の助け私を、.....
私はもう一度試してみましょう。これを良い方法として提案しているように、サムネイルを使用してテーブルビューで画像を表示する方法を教えてください。 – Sabby
こんにちは、githubからコードを使用しましたが、私はテーブルビューでイメージを取得していません。 NSString * frameImagePath = [NSString stringWithFormat:@ "http://apple.com/snapit/products/%@"、[productInfoArray valueForKey:@ "イメージ"]]; \t \t NSLog(@ "image url%@"、frameImagePath); \t \t [imageView setImageWithURL:[NSURL URLWithString:frameImagePath]プレースホルダーイメージ:[UIImage imageNamed:@ "no_image.png"]];どのように私は間違っていると教えてください...どのように使用する..ブラ... – Sabby
私は画像の仲間を得た、URLはブロックされたthatsなぜ、今私はそれをテストしますiphone.Hopeすべてうまくいくだろう。 – Sabby