おそらく非常に簡単な (ばかげた) 質問ですが、私は 4 時間ほど立ち往生しています。SOで多くのアイテムを検索しましたが、何が間違っているのかわかりません。最近、IOS の開発を開始しました。
私がやろうとしていること: メインビュー内にテーブルを持つユーティリティ アプリケーションがあります。テーブルをコードで動的に埋めようとしました。
.h ファイル
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, UITableViewDataSource,UITableViewDelegate>
{
NSArray *JSONArray;
}
@property (nonatomic, weak) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet NSArray *JSONArray;
@property (nonatomic, retain) IBOutlet NSArray *dynamicTable;
@end
.m ファイル
@interface MainViewController () {
NSMutableArray *_objects;
}
@end
@implementation MainViewController
@synthesize JSONArray;
@synthesize tableview;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableview.delegate = self;
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableview insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableview reloadData];
});
}
表を埋めるために、デフォルトのIOSの例を使用しました(投稿の下)
アプリを起動すると、 numberOfRowsInSection 、 cellForRowAtIndexPath などが読み込まれません。私は何を間違っていますか?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}