我正在尝试实现-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
到目前为止,这是我在第一个UITableViewController中所做的:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
secondviewcontroller *vc = [[secondviewcontroller alloc]init];
BudgetPlan *tempBudget = [self.budgetElements objectAtIndex:indexPath.row];
vc.budgetPlan = tempBudget;
}我的第二个视图控制器有ff:
// secondviewcontroller.h
@property (strong, nonatomic) BudgetPlan *budgetPlan;
//secondviewcontroller.m
@synthesize budgetPlan = _budgetPlan
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@ was passed with %@",self.budgetPlan.name, self.budgetPlan.amount);
self.budgetName.text = _budgetPlan.name;
self.amountBudgeted.text = [NSString stringWithFormat:@"%.02f", _budgetPlan.amount];
}不幸的是,NSLog显示为空。因此,UILabels budgetName.text和amountBudgeted.text也为空。
我已经设置了数据源并委托给包含UITableView元素(这不是UITableViewController)的自定义UIViewController。看起来我正在传递对象,但它似乎并没有传递...
我哪里错了?
发布于 2012-03-27 08:10:16
谢谢大家。问题似乎是我对故事板的使用。这
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath方法似乎只有在不使用故事板的情况下才有效。
我用Segues来回答这个问题。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"showDetailsOfBudget"])
{
NSIndexPath *indexPath = [self.budgetsTable indexPathForSelectedRow];
BudgetDetailsViewController *detailsViewController = [segue destinationViewController];
detailsViewController.budget = [self.budgetPlan.budgets objectAtIndex:indexPath.row];
}
}https://stackoverflow.com/questions/9831573
复制相似问题