Iphone 如何在UITableViewCell中添加图片
我不熟悉Iphone应用程序开发和objective C。 我想知道是否有办法在UITableViewCell中插入图片-创建自定义单元格还是不创建自定义单元格 我希望将其定位在“第二行”,与“cell.detailTextLabel.text”的显示方式相同Iphone 如何在UITableViewCell中添加图片,iphone,objective-c,Iphone,Objective C,我不熟悉Iphone应用程序开发和objective C。 我想知道是否有办法在UITableViewCell中插入图片-创建自定义单元格还是不创建自定义单元格 我希望将其定位在“第二行”,与“cell.detailTextLabel.text”的显示方式相同 有什么建议吗?提前感谢。自定义单元格是执行此操作的标准方式。网上有很多关于这方面的教程,例如。自定义单元格是实现这一点的标准方法。在线上有很多关于此的教程,例如您的table controller中的。: - (UITableViewCe
有什么建议吗?提前感谢。自定义单元格是执行此操作的标准方式。网上有很多关于这方面的教程,例如。自定义单元格是实现这一点的标准方法。在线上有很多关于此的教程,例如您的table controller中的。:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithFrame:CGZeroRect];
CGRect cellFrame = cell.frame;
NSInteger offetXInCell = 3, offsetYInCell = 7;
cellFrame.origin.x += offsetXInCell;
cellFrame.origin.y += offsetYInCell;
[cell setFrame:cellFrame];
UIImage *newImage = [UIImage imageNamed:@"MyPicture"];
cell.image = newImage;
// .... other initializations of cell
return cell;
}
我想知道它是否会起作用。你应该把你的数字用偏移量表示 在您的表格控制器中:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithFrame:CGZeroRect];
CGRect cellFrame = cell.frame;
NSInteger offetXInCell = 3, offsetYInCell = 7;
cellFrame.origin.x += offsetXInCell;
cellFrame.origin.y += offsetYInCell;
[cell setFrame:cellFrame];
UIImage *newImage = [UIImage imageNamed:@"MyPicture"];
cell.image = newImage;
// .... other initializations of cell
return cell;
}
我想知道它是否会起作用。你应该把你的数字用偏移量表示 检查tableview套件示例代码检查tableview套件示例代码您只需将图片作为单元格的子视图添加UIImageView即可。它将以两种方式工作——创建自定义单元格和不创建自定义单元格 下面是一些示例代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *kCellID = [NSString stringWithFormat:@"%d", indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
UIImageView *MyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100.0, 33.0, 300.0, 110.0)]; //put your size and coordinates here
MyImageView.image = [UIImage imageNamed:@"MyImage.png"];
[cell.contentView addSubview: MyImageView];
[MyImageView release];
return cell;
}
您只需将图片作为单元格的子视图添加到UIImageView即可。它将以两种方式工作——创建自定义单元格和不创建自定义单元格 下面是一些示例代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *kCellID = [NSString stringWithFormat:@"%d", indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
UIImageView *MyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100.0, 33.0, 300.0, 110.0)]; //put your size and coordinates here
MyImageView.image = [UIImage imageNamed:@"MyImage.png"];
[cell.contentView addSubview: MyImageView];
[MyImageView release];
return cell;
}