私は初心者プログラミングのiOSです。新しいセルをUITableViewオブジェクトに追加する際に問題があります。私はストーリーボードを使用しています。シーンの1つは、テキストフィールド、テーブルビューなどの複数のサブビューを持つUIViewControllerです。詳細シーンからこのテーブルビューに行を追加しようとしています。UITableViewに行を追加することができません
最初はテーブルに行を追加できますが、後で行を追加することはできません。行を追加するためにボタンを押すと、メソッド '[self.stepsListTableView reloadData];が呼び出されます。メソッド ' - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section'を呼び出し、新しい配列要素を含む正しい値を返します。しかし、メソッド ' - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath'は、テーブルを更新するために呼び出されません。
私は間違っていることを理解していません。私のソースコードの
詳細:ストーリーボードでも
WorkoutDetailsViewController.h
(…)
@interface WorkoutDetailsViewController : UIViewController <StepDetailsViewControllerDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, weak) id <WorkoutDetailsViewControllerDelegate> delegate;
@property (nonatomic, strong) Workout *workout;
(…)
@property (nonatomic, retain) IBOutlet UITableView *stepsListTableView;
(…)
WorkoutDetailsViewController.m
(…)
@synthesize stepsListTableView;
(…)
- (void)viewDidLoad
{
[super viewDidLoad];
addButton.enabled = FALSE;
workoutNameField.delegate = self;
if (self.workout == nil) {
self.workout = [[Workout alloc] init];
self.stepsListTableView = [[UITableView alloc] init];
}
self.stepsListTableView.delegate = self;
self.stepsListTableView.dataSource = self;
}
(…)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return [self.workout.stepsList count];
NSInteger counter = 0;
counter = [self.workout.stepsList count];
return counter;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set up the cell...
// Pending
return cell;
}
- (void)stepDetailsViewControllerDidDone:(StepDetailsViewController *)controller
{
[self.workout.stepsList addObject:controller.step];
NSInteger counter = [self.workout.stepsList count];
[self.stepsListTableView beginUpdates];
NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:(counter-1) inSection:0]];
[self.stepsListTableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[self.stepsListTableView endUpdates];
[self.stepsListTableView reloadData];
}
(…)
、私がすべきセットアップ店デリゲートとデータソースを持っていますコントローラビュー。
よろしく、 JoanBa
最初に行を追加できますが、それ以降は追加できないということはどういう意味ですか? – alecnash