我正在尝试在我的应用程序中创建一个即将发生的事件表,但是当我选择一行时 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 导致“测试”标签为“Title1”
视图确实出现了
_test.text = [upcommingTitle objectAtIndex:self.datesTable.indexPathForSelectedRow.row];
谢谢你的帮助