我使用 MFSideMenu 控制器来实现大多数具有侧边菜单功能的应用程序。所有应用程序在 iOS 7 及之前版本上都能正常工作,但在运行 iOS 8 的 iPhone 6 设备上则不行(在运行 iOS 8 的 iPhone 5 上可以正常工作)。
我似乎无法弄清楚该怎么做才能解决我正在收到的这个错误。当点击左侧菜单 UITableView 上的单元格时,应用程序会崩溃并显示此错误。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fc492877e00 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7fc492634860>
注意:UITableView是一个XIB IBOutlet。
以下是代码示例。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// This will remove extra space on top of the tableview
self.automaticallyAdjustsScrollViewInsets = NO;
// This will remove extra separators from tableview
self.tblViewMenu.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// menu titles
arrMenu = [Config returnArrLeftMenu];
// check login status
[self checkLoginStatus];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
MenuCell *mCell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
// menu cell
if (mCell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[MenuCell class]])
mCell = (MenuCell *)oneObject;
}
mCell.selectionStyle = UITableViewCellSelectionStyleBlue;
mCell.contentView.backgroundColor = [UIColor clearColor];
mCell.backgroundColor = [UIColor clearColor];
mCell.lblTitle.text = [arrMenu objectAtIndex:indexPath.row];
return mCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// load selected menu view on to the MAinViewController
MainViewController *mainController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
mainController.title = [arrMenu objectAtIndex:indexPath.row];
mainController.menuIndex = (int)indexPath.row;
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
NSArray *controllers = [NSArray arrayWithObject:mainController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}