' NSInternalInconsistencyException'错误' MVFloatingButton'

时间:2016-05-29 16:47:29

标签: objective-c memory-management tableview dealloc

我已经在网上搜索了很多关于这个问题但是我还没有设法解决它,所以不得不转而发布这个问题。

我在我的应用中使用浮动按钮;我通过Cocoapods将库包含在我的Podfile中。 Pod库是MVFloatingButton'。应用程序工作正常,直到我添加浮动按钮。

请在TableView上找到浮动按钮的屏幕截图(在iOS模拟器中运行)

enter image description here

我遇到的问题是我的TableView。浮动按钮在tableView上显示正常但是当我导航回主屏幕时,我的应用程序崩溃并出现以下错误:

*由于未捕获的异常而终止应用程序' NSInternalInconsistencyException',原因:'类UITableView的实例0x7a8a5000已取消分配,而键值观察者仍在其中注册。目前的观察资料:(  上下文:0x0,属性:0x79f91d10>  上下文:0x0,属性:0x79f92bf0>  上下文:0x0,属性:0x79f93000> )' * 第一次抛出调用堆栈: (     0 CoreFoundation 0x036a1494 __exceptionPreprocess + 180     1 libobjc.A.dylib 0x0315be02 objc_exception_throw + 50     2 CoreFoundation 0x036a13bd + [NSException raise:format:] + 141     3基础0x02d94097 NSKVODeallocate + 353     4 UIKit 0x020cf348 - [UIView(UIKitManual)发布] + 142     5 libobjc.A.dylib 0x0316e34f objc_release + 47     6 libobjc.A.dylib 0x0316f52d _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 371     7 CoreFoundation 0x035718a8 _CFAutoreleasePoolPop + 24     8 CoreFoundation 0x035a943c __CFRunLoopRun + 2364     9 CoreFoundation 0x035a8846 CFRunLoopRunSpecific + 470     10 CoreFoundation 0x035a865b CFRunLoopRunInMode + 123     11 GraphicsServices 0x0662a664 GSEventRunModal + 192     12 GraphicsServices 0x0662a4a1 GSEventRun + 104     13 UIKit 0x017dfeb9 UIApplicationMain + 160     14 NHSF 0x00096afa main + 138     15 libdyld.dylib 0x04865a25 start + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止

这是我的.m文件的代码:

#import "NHSFAdminTeamTableViewController.h"
#import "Admin.h"
#import "UIScrollView+FloatingButton.h"

#define getURLData @"http://dbchudasama.webfactional.com/jsonscriptAdmin.php"

static NSString *CellIdentifier = @"Cell";


@interface NHSFAdminTeamTableViewController () <MEVFloatingButtonDelegate>

@end

@implementation NHSFAdminTeamTableViewController

@synthesize jsonArray, AdminArray;


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Load data
    [self retrieveData];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    //v3.0 -- Initialising Floating Button
    MEVFloatingButton *button = [[MEVFloatingButton alloc] init];
    button.animationType = MEVFloatingButtonAnimationNone;
    button.displayMode = MEVFloatingButtonDisplayModeAlways;
    button.position = MEVFloatingButtonPositionBottomRight;
    button.image = [UIImage imageNamed:@"ic_create_white_24dp"];
    //button.imageColor = [UIColor groupTableViewBackgroundColor];
    button.backgroundColor = [UIColor orangeColor];
    button.outlineColor = [UIColor blackColor];
    button.outlineWidth = 0.0f;
    button.imagePadding = 15.0f;
    button.horizontalOffset = -22.0f;
    button.verticalOffset = -70.0f;
    button.shadowColor = [UIColor blackColor];
    button.shadowOffset = CGSizeMake(3, 3);
    button.shadowOpacity = 0.6f;
    button.shadowRadius = 3.0f;
    button.rounded = YES;
    button.hideWhenScrollToTop = NO;

    [self.tableView setFloatingButtonView:button];
    [self.tableView setFloatingButtonDelegate:self];
    //v3.0 --
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //Setting row selection to no for entire table so user can't select an rows. READ ONLY!
    tableView.allowsSelection = NO;

    // Return the number of rows in the section.
    return [self.AdminArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    // Configure the cell...
    Admin *idObject;

    //Grab the current object in indexPath and set it to Team Coordinator object
    idObject = [AdminArray objectAtIndex:indexPath.row];

    cell.textLabel.text = idObject.AdminRole;
    cell.detailTextLabel.text = idObject.Name;

    //Accessory
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


//Method to retrieve data from database
-(void)retrieveData
{
    //Passing in the URL of the database
    NSURL *url = [NSURL URLWithString:getURLData];

    //Creating object of the database data
    NSData *data = [NSData dataWithContentsOfURL:url];

    jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

    //Set up the TC array
    AdminArray = [[NSMutableArray alloc] init];

    //Loop through the jsonArray
    for (int i=0; i < jsonArray.count; i++) {

        //Create the Team Coordinator object
        //NSString *eID = [[jsonArray objectAtIndex:i] objectForKey:@"id"];
        NSString *aRole = [[jsonArray objectAtIndex:i] objectForKey:@"AdminRole"];
        NSString *aName = [[jsonArray objectAtIndex:i] objectForKey:@"Name"];
        //NSString *eTime = [[jsonArray objectAtIndex:i] objectForKey:@"eventTime"];
        //NSString *eLocation = [[jsonArray objectAtIndex:i] objectForKey:@"eventLocation"];

        //Now, add the Team Coordinator object to our TC array
        [AdminArray addObject:[[Admin alloc] initWithAdminTeam:aRole andName:aName]];
    }

    //Reload the table data
    [self.tableView reloadData];
}

//v3.0 -- Delegate Methods for Floating Button 
#pragma mark - MEScrollToTopDelegate Methods

- (void)floatingButton:(UIScrollView *)scrollView didTapButton:(UIButton *)button {
    NSLog(@"didTapButton");
    //[self.tableView setContentOffset:CGPointMake(0, -self.tableView.contentInset.top) animated:YES];
}

- (void)floatingButtonWillAppear:(UIScrollView *)scrollView {
    NSLog(@"floatingButtonWillAppear");
}

- (void)floatingButtonDidAppear:(UIScrollView *)scrollView {
    NSLog(@"floatingButtonDidAppear");
}

- (void)floatingButtonWillDisappear:(UIScrollView *)scrollView {
    NSLog(@"floatingButtonWillDisappear");
}

- (void)floatingButtonDidDisappear:(UIScrollView *)scrollView; {
    NSLog(@"floatingButtonDidDisappear");
}
//v3.0 --

@end

据我所知,我认为这与&#39; dequeueReusableCellWithIithntifier&#39; 有关,但我并非百分百肯定。

这是我的.h文件:

#import <UIKit/UIKit.h>

@interface NHSFAdminTeamTableViewController : UITableViewController

@property (strong, nonatomic) NSMutableArray *jsonArray;
@property (strong, nonatomic) NSMutableArray *AdminArray;


#pragma mark - Class Method
-(void)retrieveData;


//v3,0 -- Delegate Method Constructors for Floating Button
#pragma mark - MEScrollToTopDelegate Methods

- (void)floatingButton:(UIScrollView *)scrollView didTapButton:(UIButton *)button;
- (void)floatingButtonWillAppear:(UIScrollView *)scrollView;
- (void)floatingButtonDidAppear:(UIScrollView *)scrollView;
- (void)floatingButtonWillDisappear:(UIScrollView *)scrollView;
- (void)floatingButtonDidDisappear:(UIScrollView *)scrollView;
//3.0 --

@end

任何帮助都会有很大的帮助!谢谢!

0 个答案:

没有答案