- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我升级 iOS7 的应用程序时,我的一个 UITableViews 遇到了问题,该 View 附加了一个 SearchBar。我计划在更新中使用包含 TableView 和 SearchBar 的 UIViewController,但我不知道如何让它在这种组合中运行。
这是我的 .h 文件
#import <UIKit/UIKit.h>
@interface lsoNewKE_Table : UIViewController <UISearchDisplayDelegate, UISearchBarDelegate, NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
NSMutableArray * filteredListContent;
NSMutableArray * filteredList;
BOOL isSearchContent;
@private
NSFetchedResultsController *fetchedResultsController__;
NSManagedObjectContext *managedObjectContext__;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSMutableArray *keTableData;
@property (nonatomic, retain) NSMutableArray *filteredListContent;
@property (nonatomic, retain) NSMutableArray *filteredList;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
- (void)readDataForTable;
@end
这是.m文件
#import "lsoNewKE_Table.h"
#import "TblKE.h"
#import "CoreDataHelper.h"
#import "lsoAppDelegate.h"
// #import "lsoDetailViewKE.h"
#import "lsoTableViewCell.h"
@interface lsoNewKE_Table ()
@end
@implementation lsoNewKE_Table
@synthesize keTableData, managedObjectContext=managedObjectContext__, filteredListContent, filteredList, tableView, fetchedResultsController=fetchedResultsController__;
- (void)reloadFetchedResults:(NSNotification*)note {
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
if (note) {
NSLog(@"reloadFetchedResults");
[self readDataForTable];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.keTableData count]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadFetchedResults:) name:@"RefreshAllViews" object:[[UIApplication sharedApplication] delegate]];
[super viewDidLoad];
UIColor* bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"amazonas.png"]];
[self.view setBackgroundColor:bgColor];
[self readDataForTable];
isSearchContent = FALSE;
self.searchDisplayController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchDisplayController.searchBar;
}
- (void)viewWillAppear:(BOOL)animated
{
// Repopulate the array with new table data
[self readDataForTable];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[super viewDidUnload];
self.filteredListContent = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)readDataForTable
{
lsoAppDelegate *appDelegate = (lsoAppDelegate *)[[UIApplication sharedApplication] delegate];
// Grab the data
keTableData = [CoreDataHelper getObjectsForEntity:@"TblKE" withSortKey:@"desc" andSortAscending:YES andContext:appDelegate.managedObjectContext];
// Force table refresh
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.tableView == self.searchDisplayController.searchResultsTableView)
{
return [self.filteredListContent count];
}
else
{
return [keTableData count];
}
}
// Create / reuse a table cell and configure it for display
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCellKE";
lsoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects;
topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellKE_iPhone" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (lsoTableViewCell *) currentObject;
}
}
}
TblKE *currentCell;
// Get the core data object we need to use to populate this table cell
if (self.tableView == self.searchDisplayController.searchResultsTableView)
{
self.tableView.backgroundColor = [UIColor blackColor];
currentCell = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
currentCell = [keTableData objectAtIndex:indexPath.row];
}
// Fill in the cell contents
cell.textLabel.text = [currentCell desc];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Gewicht: %@ - KE: %.1f", [currentCell gewicht], [[currentCell ke]doubleValue]];
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell.imageView.image = [UIImage imageWithData:[currentCell picture]];
return cell;
}
// Swipe to delete has been used. Remove the table item
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
lsoAppDelegate *appDelegate = (lsoAppDelegate *)[[UIApplication sharedApplication] delegate];
// Get a reference to the table item in our data array
TblKE *itemToDelete = [self.keTableData objectAtIndex:indexPath.row];
// Delete the item in Core Data
[appDelegate.managedObjectContext deleteObject:itemToDelete];
// Remove the item from our array
[keTableData removeObjectAtIndex:indexPath.row];
// Commit the deletion in core data
NSError *error;
if (![appDelegate.managedObjectContext save:&error])
NSLog(@"Failed to delete Entry item with error: %@", [error domain]);
// Delete the row from the data source
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearchContent == TRUE){
[self performSegueWithIdentifier:@"EditPicture" sender:self];
} else {
[self performSegueWithIdentifier:@"EditPicture" sender:nil];
}
}
#pragma mark -
#pragma mark Content Filtering
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose name matches searchText; add items that match to the filtered array.
*/
for (TblKE *itemToSearch in keTableData)
{
NSComparisonResult result = [itemToSearch.desc compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:itemToSearch];
isSearchContent = TRUE;
}
}
}
#pragma mark -
#pragma mark UISearchDisplayController Delegate Methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:nil];
return YES;
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
isSearchContent = FALSE;
}
#pragma mark -
#pragma mark Fetched results controller
- (NSFetchedResultsController *)fetchedResultsController
{
lsoAppDelegate *appDelegate = (lsoAppDelegate *)[[UIApplication sharedApplication] delegate];
if (fetchedResultsController__ != nil)
{
return fetchedResultsController__;
}
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TblKE" inManagedObjectContext:appDelegate.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:25];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptorName = [[NSSortDescriptor alloc] initWithKey:@"desc" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptorName, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return fetchedResultsController__;
}
@end
任何帮助将不胜感激。
谢谢英格玛
抱歉斯图尔特,你是对的,应该指出我的问题......
输入搜索词时,搜索栏会变得困惑,无论我在字段中输入什么内容,它总是会出现这样的情况:
我在 cellForRowAtIndexPath 中的以下位置设置了一个断点,但它从未遇到过它。
if (self.tableView == self.searchDisplayController.searchResultsTableView)
{
self.tableView.backgroundColor = [UIColor blackColor];
currentCell = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
currentCell = [keTableData objectAtIndex:indexPath.row];
}
最佳答案
看起来像两个半透明的桌面 View 。尝试将 background-colour
设置为
searchtableview
(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller;
关于ios - 包含 TableView 的 UIViewController 中的 UISearchBar 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19098565/
我希望能够在代码中布局我的 View Controller ,但可以看到界面构建器中显示的布局。 我知道我可以创建一个 UIView 子类,使其 IBDesignable,并将其分配给 View Co
我有一个父 UIViewController(MainVC)。从那里我有 2 个 segue 到 2 个 UIViewControllers:FirstVC(标识符:goFirstVC)和 Secon
我有一个导航 Controller 。第一个viewcontroller 是FirstViewController 的一种。当我在 FirstViewController 中点击一个按钮时,它会将第二
我有一个自定义的动画 UIViewController 过渡,似乎 iOS 中有一个错误会破坏横向布局。在主要动画方法中,我得到了横向和纵向 View 的混合。 (纵向 View 都是纵向的,所以没问
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我有一个 UIViewController,里面有 UITabBar。我正在尝试模仿 UITabBarController。 My question is how do I set or a UIVi
是否有任何方便的方法来确定是否正在从处于后台模式的应用加载 View ? 在 3.X 中,我将依赖 viewDidLoad 进行一些初始化等操作,但是对于 4.X 而言情况并非如此,因为您不能依赖调用
我将主视图 Controller 作为带有 UICollectionView 的 View Controller ,并且填充了照片。 一旦一个单元格被点击,一个新的 View Controller 被
我有一个简单的 UIViewController(单点触控),在 UI 上有一个按钮。现在,我的用例很简单 - 我想在单击按钮时重新加载 UIViewController。在某些线程上,我读到我只需要
我在它上面有一个 UIViewController 1 UIButton(添加为 subview ),在我按下 Button(见下面的图 1)之后,在它上面添加了另一个 UIViewControlle
尝试为 iPad 制作基于 Storyboard的应用程序。在其中,我需要从开始屏幕 (UIViewController) 过渡到主屏幕 (UISplitViewController),然后再到全屏
我想调整 UIViewController 的大小在 Storyboard中,所以我可以使用它的 UIViewController作为弹出 View 。 在大多数网站上,我可以读到这些操作是: 拖一个
我正在尝试从 XIB 或 Storyboard加载 ViewModel 绑定(bind)的 ViewController(使用 MvvmCross 5.0.6)。我的应用程序的逻辑是,该 View C
我正在构建一个锻炼应用程序。我的 TableViewController 中有一系列练习,每个单元格显示不同的练习。单元格转到 UIViewController。在 UIViewController
我正在尝试从 XIB 或 Storyboard加载 ViewModel 绑定(bind)的 ViewController(使用 MvvmCross 5.0.6)。我的应用程序的逻辑是,该 View C
我有一个 UIViewController,它有一个模式窗口,我想在整个界面上展示它,包括 UITabBar。 我的应用程序层次结构是这样的: UITabBarController (A) ->
我想显示另一个 ViewController 的缩小“预览”在另一个 ViewController .这可能吗?不需要交互,因此它基本上可以是屏幕截图,但按比例缩小。我可以通过手动截屏并将其保存为图像
我正在开发一个应用程序,其中 UIViewController ( firstViewController ) 包含一些 UILabels , 一个 UIButton , 和 UIView ( sub
我的标签栏中有五个标签栏项目。第五项是弹出ViewController。因此,当我单击该按钮时,当前 Controller 中将显示一个弹出窗口。我使用 UIViewController 作为子类来实
我正在开发 iOS 应用程序。 我的应用程序有 6 个按钮,每个按钮都有每个标签栏控件。 so Main screen is [btn1] [btn2] [btn3] [btn4] [btn5] [b
我是一名优秀的程序员,十分优秀!