Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为UITableView';分配自定义视图时,已加载nib,但未设置视图出口;s头_Iphone_Objective C_Ios_Xcode_Cocoa Touch - Fatal编程技术网

Iphone 为UITableView';分配自定义视图时,已加载nib,但未设置视图出口;s头

Iphone 为UITableView';分配自定义视图时,已加载nib,但未设置视图出口;s头,iphone,objective-c,ios,xcode,cocoa-touch,Iphone,Objective C,Ios,Xcode,Cocoa Touch,我正在尝试为UITableView标题创建自定义视图,但不幸的是,我遇到了一个异常: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ImagesView" nib but the view outlet was not set.' 首先,

我正在尝试为
UITableView
标题创建自定义视图,但不幸的是,我遇到了一个异常:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ImagesView" nib but the view outlet was not set.'
首先,我在HomeViewController中创建了一个tableView,然后使用xib文件创建了ImagesViewController,在这里设计了我的自定义视图

最后,我尝试将ImagesView指定为我的tableView的标题:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    ImagesViewController *imagesView = [[ImagesViewController alloc] init];
    tableView.tableHeaderView = imagesView.view;

}
我做错了什么?我是iOS开发的新手,我自己就知道了


谢谢你的帮助

您可以使用此方法创建自定义标题视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
这是我的一部分

例如,我的一个应用程序使用此方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *customHeaderView = [[UIView alloc] init];
    customHeaderView.frame = CGRectMake(40.0, 20.0, 300.0, 45.0);
    UILabel *headerText = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 300, 32)];
    headerText.textAlignment = UITextAlignmentCenter;
    headerText.font = [UIFont systemFontOfSize:FONT_SIZE_FOOTER];
    headerText.numberOfLines = 0;
    headerText.backgroundColor = [UIColor clearColor];
    if (section == 0) {
        headerText.text = @"";
    }
    if (section == 1) {
        headerText.text = SETTINGS_TEXT_PART0;
    }
    [customHeaderView addSubview:headerText];
    return customHeaderView;
}

可以使用此方法创建自定义标题视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
这是我的一部分

例如,我的一个应用程序使用此方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *customHeaderView = [[UIView alloc] init];
    customHeaderView.frame = CGRectMake(40.0, 20.0, 300.0, 45.0);
    UILabel *headerText = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 300, 32)];
    headerText.textAlignment = UITextAlignmentCenter;
    headerText.font = [UIFont systemFontOfSize:FONT_SIZE_FOOTER];
    headerText.numberOfLines = 0;
    headerText.backgroundColor = [UIColor clearColor];
    if (section == 0) {
        headerText.text = @"";
    }
    if (section == 1) {
        headerText.text = SETTINGS_TEXT_PART0;
    }
    [customHeaderView addSubview:headerText];
    return customHeaderView;
}

尝试这种方法,在tableviewcontroller本身的xib文件中,将uiview或imageview(此处为标题进行设计)拖到工作区域,但不要拖到mainview或tableview中,然后制作一个名为header的iboutlet,然后将此iboutlet连接到视图,然后在tableviewcontroller中委托方法实现

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return header;
}

添加此

尝试这种方式,在tableviewcontroller自身的xib文件中,将uiview或imageview(此处对标题进行设计)拖动到工作区域,但不拖动到mainview或tableview,然后制作一个名为header的iboutlet,然后将此iboutlet连接到视图,然后在TableViewController中委托方法实现

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return header;
}

将此

添加到
ImagesViewController
中,您可能尚未将
视图
插座与视图链接。您可以在界面生成器中单击文件的所有者,然后从实用程序中单击连接检查器,将
视图
出口链接到
ui视图
,在
ImagesViewController
中,您可能还没有将
视图
出口链接到视图。您可以在界面生成器中单击文件的所有者,然后从实用程序中单击连接检查器,在那里您可以将
视图
出口链接到您的
ui视图

使用这一行代码

 {   
 ImageViewcontroller *imageView=[[ImagesViewController alloc]initwithnibname:@"ImageViewController" bundle:nil];       
 }
使用这行代码

 {   
 ImageViewcontroller *imageView=[[ImagesViewController alloc]initwithnibname:@"ImageViewController" bundle:nil];       
 }

您还可以调用viewcontroller nib file.like this ImageViewcontroller*imageView=[[ImagesViewController alloc]initwithnibname:@“ImageViewcontroller”bundle:nil];谢谢,你的建议行得通!欢迎。如果评论对您有帮助,请单击我的评论中的箭头标记。如果我的代码行有效,请在下面发布我的答案,请右键标记此箭头,以便对其他人有帮助。您也可以将viewcontroller nib文件称为。类似此ImageViewcontroller*imageView=[[ImagesViewController alloc]initwithnibname:@“ImageViewController”捆绑包:无];谢谢,您的建议有效!欢迎。如果评论对您有帮助,请单击我的评论中的箭头标记。如果我的代码行有效,请在下面发布我的答案,请右键标记此箭头,以便对其他人有所帮助。