主细节情节串连板:表格视图不显示单元格(Objective-C)

主细节情节串连板:表格视图不显示单元格(Objective-C),objective-c,storyboard,Objective C,Storyboard,主视图控制器没有显示任何单元格,我遇到问题。情况就是这样: 该应用程序使用故事板 当应用程序启动时,它将转到navigationController 按下一个按钮并将其连接到table ViewController,并将其设置为“按下” 我已经添加了对象,并创建了一个单元格/详细视图或其他什么 由于某种原因,手机不会出现 以下是文件: MasterViewController.h: #import <UIKit/UIKit.h> #import "CraftingDetail.h"

主视图控制器没有显示任何单元格,我遇到问题。情况就是这样:

该应用程序使用故事板

当应用程序启动时,它将转到navigationController

按下一个按钮并将其连接到table ViewController,并将其设置为“按下”

我已经添加了对象,并创建了一个单元格/详细视图或其他什么

由于某种原因,手机不会出现

以下是文件:

MasterViewController.h:

#import <UIKit/UIKit.h>
#import "CraftingDetail.h"
#import "Crafting.h"

@class CraftingList;

@interface CraftingMaster : UITableViewController

@property (strong, nonatomic) CraftingDetail *detailViewController;
@property (strong, nonatomic) CraftingList *CL;

@end
#import <UIKit/UIKit.h>

@interface CraftingDetail : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *Image;
@property (strong, nonatomic) IBOutlet UITextView *Description;

@end
#导入
#导入“CraftingDetail.h”
#导入“Crafting.h”
@类工艺列表;
@界面制作大师:UITableViewController
@属性(强,非原子)CraftingDetail*detailViewController;
@属性(强,非原子)工艺列表*CL;
@结束
MasterViewController.m:

#import "CraftingMaster.h"
#import "CraftingList.h"

@interface CraftingMaster ()

@end

@implementation CraftingMaster

@synthesize detailViewController = _detailViewController;
@synthesize CL;

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

- (void)viewDidLoad
{
    [super viewDidLoad];

    // 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;
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return  self.CL.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.CL.count;
}

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

    // Configure the cell...

    cell.textLabel.text = [self.CL craftingAtIndex:indexPath.row].Title;

    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 - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc]   initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end
#导入“CraftingMaster.h”
#导入“CraftingList.h”
@接口工艺大师()
@结束
@实现工艺大师
@综合detailViewController=\u detailViewController;
@合成氯;
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
self.CL=[[CraftingList alloc]init];
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
self.navigationItem.rightBarButtonItem=self.editButtonItem;
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回节数。
返回self.CL.count;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
//返回节中的行数。
返回self.CL.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//配置单元格。。。
cell.textlab.text=[self.CL craftingAtIndex:indexath.row].Title;
返回单元;
}
/*
//替代以支持表视图的条件编辑。
-(BOOL)tableView:(UITableView*)tableView caneditrowatinexpath:(nsindepath*)indepath
{
//如果不希望指定的项可编辑,则返回“否”。
返回YES;
}
*/
/*
//替代以支持编辑表格视图。
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径
{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从数据源中删除该行
[tableView deleteRowsAtIndexPaths:@[indexPath]和RowAnimation:UITableViewRowAnimationFade];
}   
else if(editingStyle==UITableViewCellEditingStyleInsert){
//创建相应类的新实例,将其插入数组,并向表视图添加新行
}   
}
*/
/*
//替代以支持重新排列表视图。
-(void)tableView:(UITableView*)tableView移动rowatinexpath:(nsindepath*)从indepath到indepath:(nsindepath*)到indepath
{
}
*/
/*
//重写以支持表视图的条件重新排列。
-(BOOL)tableView:(UITableView*)tableView可以移动rowatinexpath:(nsindepath*)indepath
{
//如果不希望该项目可重新订购,则返回“否”。
返回YES;
}
*/
#pragma标记-表视图委托
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
//导航逻辑可能位于此处。创建并推送另一个视图控制器。
/*
*detailViewController=[[alloc]initWithNibName:@“bundle:nil];
// ...
//将选定对象传递给新的视图控制器。
[self.navigationController pushViewController:detailViewController动画:是];
*/
}
@结束
DetailViewController.h:

#import <UIKit/UIKit.h>
#import "CraftingDetail.h"
#import "Crafting.h"

@class CraftingList;

@interface CraftingMaster : UITableViewController

@property (strong, nonatomic) CraftingDetail *detailViewController;
@property (strong, nonatomic) CraftingList *CL;

@end
#import <UIKit/UIKit.h>

@interface CraftingDetail : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *Image;
@property (strong, nonatomic) IBOutlet UITextView *Description;

@end
#导入
@界面工艺细节:UIViewController
@属性(强,非原子)IBUIImageView*图像;
@属性(强,非原子)IBUITextView*说明;
@结束

这是一个老问题,但在开始使用表视图开发时,表视图意外为空是一个常见问题,因此希望这个答案对某些人有用

当您的表视图中没有单元格时,您需要检查以下几点:

  • 您的数据源对象(在本例中为self.CL)是否有效?(即,它们是否
    !=nil
    并指向正确的对象?)
  • numberOfsectionsTableView:
    是否返回大于零的整数值
  • tableView:numberOfRowsInSection
    :是否返回大于零的整数值
下面是上面MasterViewController.m中需要注意的几个问题: