表视图不会推送到下一个视图

时间:2013-12-23 23:19:08

标签: ios objective-c xcode uitableview xcode5

我有一个下拉文本字段的代码,这样当用户单击表视图中的一行时,它会推送到下一个视图,但由于某种原因,这不会发生。我的代码有问题吗?因为应用程序没有崩溃我没有错误警告,也不知道为什么它不起作用。

- (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];
}

2 个答案:

答案 0 :(得分:1)

您很可能没有设置UITableView实例的委托,因此不会调用任何委托方法,例如-didSelectRowAtIndexPath。

[self.tableView setDelegate:self]

答案 1 :(得分:0)

确保您在app delegate中编写了导航控制器代码,并在当前视图控制器中设置了tableview委托,然后编写此

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
  // in tableview you will be passing information from an array/dictionary in cell configure method so use the same array/dictionary to get information also.

 [delegate dropDownCellSelected:indexPath.row];
 NSString *cellText = yourArray[indexPath.row];

 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];
 }
 /// if still app crashes enable exception break point in left menu of your Xcode this will help you to know at which line of code app crashed.
相关问题