我正在做这个 iPhone 项目,我需要在普通视图控制器内有一个(动态)表视图。我没有选择表视图控制器,因为我需要在页面中放置其他内容。想象一个包含文本字段、按钮和大约 4-5 个单元格的小表格视图的页面。
当我运行应用程序时,我需要触摸一个按钮才能转到此视图。我单击按钮,应用程序崩溃并告诉我:
2012-07-22 14:40:57.304 有多少?[3055:f803]*断言失败
-[UITableView _createPreparedCellForGlobalRow:withIndexPath:],/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
这是我的 .H 文件:
#import <UIKit/UIKit.h>
@interface ProjectViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
这是我的 .M 文件:
#import "ProjectViewController.h"
@interface ProjectViewController ()
@end
@implementation ProjectViewController
//MyViewController.m
#pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"numberOfSectionsInTableView");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"numberOfRowsInSection");
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
NSLog(@"cellForRowAtIndexPath");
cell.textLabel.text = @"Test";
return cell;
}
@end
我通过 Control 键从表视图拖动到控制器以设置委托和数据源。
我做错了什么??
感谢您的帮助。
尝试在你的生活中开辟一个出口.h
文件并将其连接到tableView
在你的storyboard
项目视图控制器.h
@property (nonatomic, strong) IBOutlet UITableView *myTableView;
项目视图控制器.m
@synthesize myTableView;
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"cell"];
NSLog(@"cellForRowAtIndexPath");
cell.textLabel.text = @"Test";
return cell;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)