点击TableViewCell,Push到一个viewcontroller,push的那个viewcontroller里面的数据是要根据cell里面的数据而定的.我想问下,每个push后视图的数据都不同,那要怎么赋值传值?
我的表格页面叫Tab2ViewController,是用xib ListTableViewCell画的,push到的页面叫DetailViewController。
#pragma mark - TableView datasource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
static NSString *CellIdentifier = @"ListTableViewCell";
ListTableViewCell *cell = (ListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSArray *nibs=[[NSBundle mainBundle] loadNibNamed:@"ListTableViewCell" owner:self options:nil];
cell = (ListTableViewCell *)[nibs objectAtIndex:0];
[cell setValue:CellIdentifier forKey:@"reuseIdentifier"];
}
//**遍历respont**//
//**liatArray是从服务器返回的数据**//
NSMutableDictionary *tempDic = [listArray objectAtIndex:indexPath.row];
cell.timeLabel.text = [NSString stringWithFormat:@"%@", [tempDic objectForKey:@"bno"]]; // 时间
NSString *percentStr = [NSString stringWithFormat:@"%@", [tempDic objectForKey:@"apr"]];
cell.percentLabel.text = percentStr;
return cell;
}
#pragma mark - UITableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 我想要在DetailViewController里面显示数据
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailViewController animated:YES];
}
你在
cellForRow
方法里不是用NSMutableDictionary *tempDic = [listArray objectAtIndex:indexPath.row];
取到了数据吗?在
didSelectRow
方法里一样呀。也这么取到数据,然后传给detailViewController
就行了呗。