【发布时间】:2011-10-02 22:18:46
【问题描述】:
我是论坛的新手,我喜欢一些帮助。我有一个表格视图,我可以通过单独页面上的不同按钮向其中添加单元格。我想让每个按钮添加一个新单元格,但图像不同。举个例子。按钮 1 将添加一个单元格和一个名为 @"button1.png" 的图像 按钮 2 将添加一个带有名为 @"button2.png" 的图像的单元格,依此类推。但是我无法将图像添加到单元格中。我可以在cellForRow 中做到这一点,但不是在按钮方法中。有人可以帮我吗?我在按钮中试过这个:
编辑 用于添加单元格和图像的按钮:
- (IBAction)outlet1:(id)sender {
[cart.cells addObject:@"1"];
[cart.cell.imageView setImage:[UIImage imageNamed:@"paddle1.png"]];
}
cellForRow
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
//cell.imageView.image = [UIImage imageNamed:@"paddle1.png"];
[myTableView reloadRowsAtIndexPaths:indexPath.row
withRowAnimation:UITableViewRowAnimationNone];
cell.textLabel.text = [cells objectAtIndex:indexPath.row];
return cell;
}
【问题讨论】:
标签: iphone cocoa-touch uitableview uiimageview