アプリで今後のイベント テーブルを作成しようとしていますが、行を選択すると indexPathForSelectedRow は常に 0 を返します。
NSArray *upcommingTitle;
NSMutableArray *upcommingSubtitle;
NSMutableArray *upcommingTime;
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)datesTable numberOfRowsInSection:(NSInteger)section
{
return upcommingTitle.count;
}
-(UITableViewCell *)tableView:(UITableView *)datesTable cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
DatesCustomCell *Cell = [datesTable dequeueReusableCellWithIdentifier:cellIdentifier];
if(!Cell)
{
Cell = [[DatesCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Cell.DatesTitle.text = [upcommingTitle objectAtIndex:indexPath.row];
Cell.DatesSubtitle.text = [upcommingSubtitle objectAtIndex:indexPath.row];
Cell.DatesTime.text = [upcommingTime objectAtIndex:indexPath.row];
return Cell;
}
self.datesTable.dataSource = self;
self.datesTable.delegate = self;
読み込み済みの表示
upcommingTitle = [[NSMutableArray alloc] initWithObjects:@"Title1", @"Title2", nil];
upcommingSubtitle = [[NSMutableArray alloc] initWithObjects:@"Sub1", @"Sub2", nil];
upcommingTime = [[NSMutableArray alloc] initWithObjects:@"Date1", @"Date2", nil];
ただし、次の例では常に 0 が返され、"test" ラベルが "Title1" になります。
ビューは表示されました
_test.text = [upcommingTitle objectAtIndex:self.datesTable.indexPathForSelectedRow.row];
助けてくれてありがとう