【发布时间】:2014-01-27 06:07:30
【问题描述】:
在我的应用程序中,当用户点击该单元格中的特定按钮时,我需要展开tableviewcell(这就像一个切换,点击将展开该行,而点击其他时间将折叠该行)。因此,我实现了自定义委托方法,以了解需要重新加载哪个单元格并使用'reloadRowsAtIndexPaths' 重新加载该特定单元格。
第一次点击按钮时它工作正常,甚至第二次点击按钮,但它在第三次时崩溃说“无法在捆绑包中加载 NIB:'NSBundle </Users/path/myApp.app> (loaded)',名称为 'ContactCell''。
我的问题是重新加载第一次和第二次工作的单元格,为什么它第三次崩溃?
我的代码:
[contactTableView beginUpdates]; // Inside the custom delegate method
[contactTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexpath] withRowAnimation:UITableViewRowAnimationNone]; // indexpath is which i get from cell through custom delegate method
[contactTableView endUpdates];
ContactTableCell *cell; //Inside the cellForRowAtIndexPath
static NSString *CellIdentifier = @"ContactCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// load a new cell from the nib file
[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
cell = self.contactCell;
cell.delegate = self;
cell.indexPath = indexPath;
self.contactCell = nil;
}
为什么会崩溃?
【问题讨论】:
-
这个单元格的笔尖是什么? ContactCell 还是 ContactTableCell?
-
@Mani ContactCell.xib。它只是偶尔崩溃,而不是所有时候。所以,笔尖名称不是我认为的问题。
-
你的tableview宽度不变?为什么不能增加tableview的宽度?
-
@footyapps27 增加 tableView 的宽度如何解决这个问题?
-
变量的开头不应使用大写字母(即 CellIdentifier -> cellIdentfier)。另外我认为您不需要在此方法中加载笔尖,您需要在
ContactTableCell类中进行
标签: ios objective-c uitableview