問題があります。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 に何も表示されないのでしょうか?