HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 加载笔尖但没有得到UITableView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_801_2@
我一直在YouTube( part 1part 2)上关注本教程.

我已经完成了两个视频,并使用以下代码将视图控制器与父视图控制器连接起来:

- (IBACtion)searchButtonClicked:(id)sender {
    NSLog(@"It works.");

    SearchViewController *searchViewControl = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchControllerNav"];

    [self presentViewController:searchViewControl animated:YES completion:nil];

}

这段代码确实有效,因为这与我用于其他模态视图控制器的格式相同,所以我知道这不是问题.

无论如何,当我点击视图控制器中的搜索按钮时,它应该弹出SearchViewController.但是,应用程序崩溃了,它给了我这个错误信息:

TerminaTing app due to uncaught exception 'NSInternalInconsistencyException',reason: '-[UITableViewController loadView] loaded the "jP7-vt-IdA-view-jer-xW-qlD" nib but didn't get a UITableView.'

我正在为这个应用程序使用Storyboard.

有什么东西我不见了吗?先感谢您.

一个附带问题:我也收到一个警告,说当指示isFiltered == YES时,指针和整数之间的比较(‘BOOL *'(又名’signed char *’)和’int’).无论如何要解决它吗?

这是SearchViewController的代码

SearchController.h

#import <UIKit/UIKit.h>

@interface SearchViewController : UITableViewController <UITableViewDelegate,UITableViewDatasource,UISearchBarDelegate> {

}
- (IBACtion)cancelButtonTapped:(id)sender;

@property (weak,nonatomiC) IBOutlet UISearchBar *mySearchBar;
@property (weak,nonatomiC) IBOutlet UITableView *myTableView;

@property (nonatomic,strong) NSMutableArray *itemsInCloudApp;
@property (nonatomic,strong) NSMutableArray *filteredList;
@property BOOL *isFiltered;


@end

SearchViewController.m

#import "SearchViewController.h"

@interface SearchViewController ()

@end

@implementation SearchViewController

@synthesize mySearchBar,myTableView,itemsInCloudApp,filteredList,isFiltered;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Set title.
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    titleLabel.text = @"Search";
    titleLabel.adjustsFontSizeToFitWidth = YES;
    titleLabel.clipsToBounds = YES;
    titleLabel.numberOfLines = 1;
    titleLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:18];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [titleLabel sizeToFit];

    self.navigationItem.titleView = titleLabel;

    // Alloc and init list.
    itemsInCloudApp = [[NSMutableArray alloc]initWithObjects:@"http://www.apple.com/",@"http://www.trijstudios.com/",@"http://www.google.com/",@"http://www.squarespace.com/",@"http://www.youtube.com/",nil];
}

- (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
{
    // Return the number of rows in the section.
    if (isFiltered == YES) {
        return [filteredList count];
    } else {
    return [itemsInCloudApp count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    if (isFiltered == YES) {
        cell.textLabel.text = [filteredList objectATindex:indexPath.row];
        cell.detailTextLabel.text = [filteredList objectATindex:indexPath.row];;
    } else {
        cell.textLabel.text = [itemsInCloudApp objectATindex:indexPath.row];
        cell.detailTextLabel.text = [itemsInCloudApp objectATindex:indexPath.row];
    }

    return cell;
}

-(void)searchBar:(UISearchBar *)searchbar textDidChange:(NSString *)searchText {
    if (searchText.length == 0) {
        // Set bollean flag
        isFiltered = NO;
    } else {
        // Set Boolean flag
        isFiltered = YES;

        // Alloc and init our fliteredData
        filteredList = [[NSMutableArray alloc] init];

        // Fast enumeration
        for (NSString *name in itemsInCloudApp) {
            NSRange nameRange = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];

            if (nameRange.LOCATIOn != NsnotFound) {
                [filteredList addObject:name];
            }
        }
    }
    // Reload tableView
    [myTableView reloadData];

}

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [mySearchBar resignFirstResponder];
}

- (IBACtion)cancelButtonTapped:(id)sender {

    [self dismissviewControllerAnimated:YES completion:nil];

}
@end

注意:我做了一些编辑以满足我的需求.

@H_801_2@

解决方法

您是否尝试将@interface SearchViewController:UITableViewController更改为@interface SearchViewController:UIViewController

我强烈怀疑你没有将你的UITableview作为View附加在XIB中,或者你的类应该派生UIViewController而不是UITableviewController类.

@H_801_2@ @H_801_2@
@H_801_2@
@H_801_2@

大佬总结

以上是大佬教程为你收集整理的ios – 加载笔尖但没有得到UITableView全部内容,希望文章能够帮你解决ios – 加载笔尖但没有得到UITableView所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。