我是相当新的论坛和id爱一些援助。我有一个表格视图,并且能够通过单独页面上的不同按钮向其添加单元格。我想让每个按钮添加一个新的单元格,但使用不同的图像。举个例子。按钮1将添加一个单元格,并且名为@"button1.png"
的图像按钮2将添加一个名为@"button2.png"
的图像的单元格等。但即时通讯无法将图像添加到单元格。我可以在cellForRow
中完成,但不能用按钮方法。有人可以帮我吗?我在按钮尝试这样做:Table view中的不同图像View?
编辑用于补充细胞和图像 按钮:
- (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;
}
好的,所以当这个方法被调用时,它会重新加载表的行,它会允许我添加新的图像到tableview行?另外我应该用foo代替什么?非常感谢答复安德鲁! :) – iProRage
使用indexPathArray调用该方法,该方法包括要更改的行的索引路径。至于'foo',请选择您想要的行动画,例如,如果您只是想立即重画UITableViewRowAnimationNone。查看此消息的文档以获取更多信息。 – AndrewS
好吧,所以我把这个代码放在cellForRow中:'[myTableView reloadRowsAtIndexPaths:indexPath.row withRowAnimation:UITableViewRowAnimationNone];'它仍然不允许添加图片。如果我添加多个单元格,然后尝试去tableView页面,应用程序崩溃。在这里,你可以阅读我的代码,在我的问题中解决它并显示我现在拥有的。非常感谢所有的帮助! – iProRage