在splitview detailview中传递值

时间:2014-02-24 12:57:09

标签: ios oop uitableview uisplitviewcontroller

我有一个splitview应用程序,一个左边是客户的表,右边是他们的信息,所以我必须通过点击的女巫客户,我不能使用这个名字,如果两个人有相同所以即时通讯传递单元格的tag属性中的客户ID,但我不能让它工作。

这是我设置值的地方,我可以看到它在调试时工作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

Customer names
NSDate *object = _objects[indexPath.row];

//Customer number
NSString *nr = _kundnr[indexPath.row];

//Customer name
cell.textLabel.text = [object description];

//Customer number
NSInteger Ftgnr = [nr intValue];

//Setting the customer number to cell tag
cell.tag = Ftgnr;

return cell;
}

在这里我拿起cell.tag它是detailview viewdidload,我尝试了很多不同的方法将id保存到变量但应用程序崩溃,我不知道该值是否通过。 它正在努力获取描述(客户名称)但我想要id。

- (void)configureView
{
// Update the user interface for the detail item.

if (self.detailItem) {

  //  NSString *strCellTag = [NSString stringWithFormat:@"%d", [self.detailItem tag]];

   //here im trying to pick up the tag value this is where the app craches
   NSInteger Ftgnr = [self.detailItem tag];

   // NSString *stringformat = [NSString stringWithFormat:@"%d", Ftgnr];

    //Its working to pick up the text from the cell
    self.detailDescriptionLabel.text = [self.detailItem description];
}

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

向详细视图控制器添加属性,以便在设置详细信息项时设置ID。然后:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.detailViewController.detailIdentity = _kundnr[indexPath.row];
    self.detailViewController.detailItem = _objects[indexPath.row];
}

然后使用self.detailIdentity代替[self.detailItem tag]。并且,它已经是一个字符串,因此您不需要转换为整数并返回。

您可能也应该:

  1. detailItem重命名为更具体,例如detailDate
  2. 考虑创建一个自定义类来保存完整的detailItem(因此它包含标识和日期)

答案 1 :(得分:0)

我的最终代码

Masterviewcontroller

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"  forIndexPath:indexPath];

NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];

return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDate *object = _objects[indexPath.row];
NSDate *kundnr = _kundnr[indexPath.row];
self.detailViewController.detailItem = object;
self.detailViewController.detailIdentity = kundnr;

}

Detailviewcontroller

- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
    _detailItem = newDetailItem;

    // Update the view.
    [self configureView];
}

if (self.masterPopoverController != nil) {
    [self.masterPopoverController dismissPopoverAnimated:YES];
}        
}

- (void)setDetailIdentity:(id)newDetailItentity
{
if (_detailIdentity != newDetailItentity) {
    _detailIdentity = newDetailItentity;

    // Update the view.
    [self configureView];
}

if (self.masterPopoverController != nil) {
    [self.masterPopoverController dismissPopoverAnimated:YES];
}
}

- (void)configureView
{
// Update the user interface for the detail item.

if (self.detailItem) {

   // NSString *stringformat = [NSString stringWithFormat:@"%d", Ftgnr];
    self.detailDescriptionLabel.text = [self.detailItem description];
}


if (self.detailIdentity) {

    NSString *kundnr = [self.detailIdentity description];

}

}