我正在构建一个带有自定义栏选项卡的简单应用程序,该选项卡ViewController
从UITableView
位于另一个ViewController
.
但是,每次我尝试在 tableview 上滚动时,都会出现exc_bad_access
错误。我启用NSzombies
并保护 malloc 以获取有关该问题的更多信息。
在控制台中我得到:
"message sent to deallocated instance 0x19182f20"
分析后我得到:
# Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller
56 0x19182f20 FirstTabBarViewController Zombie -1 00:16.613.309 0 UIKit -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging]
这是发生错误的ViewController的一些代码:.h文件:
#import <UIKit/UIKit.h>
#import "DataController.h"
@interface FirstTabBarViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView* tabBarTable;
}
@property (strong, nonatomic) IBOutlet UIView *mainView;
@property (strong, nonatomic) IBOutlet UITableView *tabBarTable;
@property (nonatomic, strong) DataController *messageDataController;
@end
.m 文件:
#import "FirstTabBarViewController.h"
#import "DataController.h"
@interface FirstTabBarViewController ()
@end
@implementation FirstTabBarViewController
@synthesize tabBarTable=_tabBarTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.messageDataController=[[DataController alloc] init];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.messageDataController countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"mainCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
};
NSString *expenseAtIndex = [self.messageDataController
objectInListAtIndex:indexPath.row];
[[cell textLabel] setText:expenseAtIndex];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
@end
这个 FirstTabBarViewController 使用以下自定义 segue 加载到 MainViewController 中:
#import "customTabBarSegue.h"
#import "MainViewController.h"
@implementation customTabBarSegue
-(void) perform {
MainViewController *src= (MainViewController *) [self sourceViewController];
UIViewController *dst=(UIViewController *)[self destinationViewController];
for (UIView *view in src.placeholderView.subviews){
[view removeFromSuperview];
}
src.currentViewController =dst;
[src.placeholderView addSubview:dst.view];
}
@end
Datacontroller 类只是一个包含字符串的简单 NSMutableArray。
我正在使用 ARC,所以我不明白内存管理错误来自哪里。有人有线索吗?
非常感谢任何帮助;)谢谢!