ios - 请求非结构或联合中的成员 tableView

标签 ios objective-c uitableview core-data

请帮助解决这个问题,我正在尝试使用 coreData db 填充我的表格单元格;

我正在将示例从 iPhone 移植到 iPad, 问题是在 iPad 中我的表格 View 中。我正在使用:

@interface FailedBanksViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate>

不是

@interface FailedBanksListViewController : UITableViewController      <NSFetchedResultsControllerDelegate>

对于整个表格 View ,但在我的 View 中的表格,

所以我得到错误:

"Request for member 'tableView' in something not a structure or union"

对于我的代码,

看看下面的代码,我希望这是唯一的问题:

#import "FailedBanksViewController.h"
#import "FailedBankInfo.h"


@implementation FailedBanksViewController
@synthesize context = _context;
@synthesize fetchedResultsController = _fetchedResultsController;


- (NSFetchedResultsController *)fetchedResultsController {

if (_fetchedResultsController != nil) {
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FailedBankInfo" inManagedObjectContext:_context];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"details.closeDate" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:_context sectionNameKeyPath:nil cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;

[fetchRequest release];
[theFetchedResultsController release];

return _fetchedResultsController;    
}


- (void)viewDidLoad {
[super viewDidLoad];


NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
    // Update to handle the error appropriately.
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    exit(-1);  // Fail
}
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}


- (void)viewDidUnload {
self.fetchedResultsController = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];

//return [array count];
//return [[fetchedResultsController sections] count];
}



- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

FailedBankInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = info.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", info.city, info.state];

}


//---insert individual row into the table view---

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
//---try to get a reusable cell---

UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];



//---create new cell if no reusable cell is available---

if (cell == nil) {

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

      }
[self configureCell:cell atIndexPath:indexPath];

return cell;


//cell.textLabel.text = [array objectAtIndex:indexPath.row]; 


//return cell;

} 



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[tableView deselectRowAtIndexPath:indexPath animated:YES];


}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}




- (void)dealloc {
[super dealloc];
}


# FROM HERE THE ERRORS!!!
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller is about to start sending change notifications, so prepare the table view for updates.
[self.tableView beginUpdates];
}


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

UITableView *tableView = self.tableView;

switch(type) {

    case NSFetchedResultsChangeInsert:
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        break;

    case NSFetchedResultsChangeDelete:
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        break;

    case NSFetchedResultsChangeUpdate:
        [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
        break;

    case NSFetchedResultsChangeMove:
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        // Reloading the section inserts a new row and ensures that titles are updated appropriately.
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        break;
}
}


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {

switch(type) {

    case NSFetchedResultsChangeInsert:
        [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
        break;

    case NSFetchedResultsChangeDelete:
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
        break;
}
}


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller has sent all current change notifications, so tell the table view to process all updates.
[self.tableView endUpdates];
}

@end

最佳答案

UIViewController 根本没有名为 tableView 的实例变量/属性。自己添加属性并实现所有必要的方法来替换 UITableViewController 或继续使用 UITableViewController 作为基类。

关于ios - 请求非结构或联合中的成员 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4506077/

相关文章:

ios - 从 Storyboard实例化的 UIViewController 扩展

ios - 使用 AFNetworking 2.0 创建自己的委托(delegate)和协议(protocol)

iphone - 最佳方法 : Read And Understand Unknown Xcode Projects

objective-c - 如何为多个子类使用单个 Storyboard uiviewcontroller

iOS 11 动画大标题显示模式

ios - 如何从 View 获取数据到 UITabBarController

ios - 无法在 Realm 中创建触发器

objective-c - 为什么在 Objective-C 中,在单独的语句中执行 alloc 和 init 会导致根据 Xcode 静态分析器释放对象?

ios - 将 tableview 添加到 scrollview 并让 scrollview 在单元格添加到 tableview 时保持高度增长

ios - UITableViewCells 未扩展以适合文本