我有一个问题,我的 UIViewController 中有一个 UITableView,但是当我将内容添加到我的 UITableView 并重新加载数据时,什么也没有发生。
我的 UIViewController:
@interface WPCreateViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate> {
....
@property (strong, nonatomic) IBOutlet UITableView *tableViewEntities;
@property (strong, nonatomic) NSMutableArray *entities;
....
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;
- (IBAction)addEntities:(id)sender;
- (IBAction)deleteEntities:(id)sender;
}
实现是这样的:
@implementation WPCreateViewController
- (void)viewDidLoad{
[super viewDidLoad];
....
[self.tableViewEntities setAllowsMultipleSelectionDuringEditing:YES];
[self.entities setArray:[[NSMutableArray alloc] init]];
....
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.entities count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellID = @"WPEntityCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
cell.textLabel.text = [[self.entities objectAtIndex:indexPath.row] name];
cell.detailTextLabel.text = [[self.entities objectAtIndex:indexPath.row] description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
}
如果我尝试添加一些东西,就像我说的那样,我有这个方法与一个按钮连接
- (IBAction)addEntities:(id)sender {
Entity *temp = [[Entity alloc] init];
temp.name = @"Test";
temp.description = @"TestTest";
[self.entities addObject:temp];
[self.tableViewEntities reloadData];
}
顺便说一句,所有连接都正确设置,那么为什么 uitableview 不显示任何内容?