0
我有一个下拉文本框的代码,这样当用户单击表格视图中的一行时,它会推入下一个视图,但由于某种原因,这不会发生。我的代码有问题吗?因为该应用程序不会崩溃,所以我没有错误警告,也不知道为什么它不起作用。表视图不会推送到下一个视图
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
[delegate dropDownCellSelected:indexPath.row];
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cellText forKey:@"keyToLookupString"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ShiftCalculatorViewController *shiftCalculatorViewController =
[[ShiftCalculatorViewController alloc] init];
[self presentViewController:shiftCalculatorViewController animated:YES
completion:nil];
}
你做几件事情是错误的。您不应该从单元获取数据 - 单元格用于显示数据,而不是用于提供数据。您应该从您用来填充表格的数组中设置cellText的值。其次,你不应该使用alloc init来获得ShiftCalculatorViewController的一个实例,除非你已经在代码中做了它的视图(没有xib或storyboard)。你应该使用initWithNibName:bundle :(如果你在xib中创建它),或者使用instantiateViewControllerWithIdentifier :(如果在故事板中创建的话)。 – rdelmar
'dropDownCellSelected'到底做了什么? –