gpt4 book ai didi

iphone - 关于 UITableView

转载 作者:行者123 更新时间:2023-11-28 19:24:23 26 4
gpt4 key购买 nike

我是 iPhone 编程的初学者...我有一个类似于照片库的应用程序,我在其中使用带有 JSON 的服务器为 UITableView 中的每个单元格加载图像和标题。当我滚动表格时,程序崩溃了!

-(NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection:(NSInteger) section {
return [id_arr count];

}

-(CGFloat) tableView : (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath {
return 80;
}

//
// tableView:cellForRowAtIndexPath:
//
// Returns the cell for a given indexPath.
//
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];


}

NSString *tmp3=[NSString stringWithFormat:@"%@",[path_arr objectAtIndex:indexPath.row]];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@" " withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSLog(@"URL:%@",tmp3);


NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:tmp3]];

//NSLog(@"Image DATA:%@",[path_arr objectAtIndex:0]);
UIImage* image1 = [[UIImage alloc] initWithData:imageData];
UIImageView *imgview=[[UIImageView alloc]initWithImage:image1];
imgview.frame=CGRectMake(5, 5, 56, 68);
imgview.backgroundColor=[UIColor redColor];
[cell.contentView addSubview:imgview];


UILabel *lbl_desc=[[UILabel alloc]initWithFrame:CGRectMake(70, 1, 240, 50)];
NSString *tmp=[NSString stringWithFormat:@"%@",[descrip_arr objectAtIndex:indexPath.row]];
tmp=[tmp stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp=[tmp stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp=[tmp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//tmp=[tmp stringByReplacingOccurrencesOfString:@" " withString:@""];
lbl_desc.text=tmp;
lbl_desc.font=[UIFont systemFontOfSize:14];
lbl_desc.lineBreakMode=UILineBreakModeWordWrap;
lbl_desc.numberOfLines=0;
lbl_desc.textAlignment=UITextAlignmentLeft;
lbl_desc.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl_desc];


NSLog(@"A_count:%@",[count_arr objectAtIndex:0]);
UILabel *lbl_page=[[UILabel alloc]initWithFrame:CGRectMake(230, 50, 100, 20)];
NSString *tmp1=[NSString stringWithFormat:@"%@",[count_arr objectAtIndex:indexPath.row]];
NSLog(@"A_count1:%@",tmp1);
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
tmp1=[tmp1 stringByAppendingString:@" Images"];
NSLog(@"A_count123:%@",tmp1);
lbl_page.text=tmp1;
lbl_page.font=[UIFont systemFontOfSize:12];
lbl_page.lineBreakMode=UILineBreakModeWordWrap;
lbl_page.numberOfLines=0;
lbl_page.textAlignment=UITextAlignmentLeft;
lbl_page.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl_page];

cell.backgroundColor=[UIColor clearColor];

[imageData release];
[image1 release];
[imgview release];
}

最佳答案

您应该在函数末尾return cell;

关于iphone - 关于 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5312314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com