我是相當新的論壇和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