从推送的视图控制器返回一个值

时间:2011-12-12 01:00:19

标签: xcode return-value

在我的代码中,我已经定制了initWithNibName来接收它需要做的事情。这是代码:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil theArray:(NSArray *)theDataArray theVal:(NSInteger)theDataValue bRange:(BOOL)isRange bColor:(BOOL)isColor{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.data = theDataArray;
        self.selectedValue = theDataValue;
        NSLog(@"NCG - initWithNibName setting selectedValue = %d.", self.selectedValue);
        //self.originalValue = theDataValue;
        self.isTheRange = isRange;
        self.isTheColor = isColor;
        self.selectedIndex = [self indexFromValue:theDataValue bRange:self.isTheRange bColor:self.isTheColor];
        self.doneClicked = NO;
        //NSLog(@"Selected Row = %d.", self.selectedIndex);
    }
    return self;
}

当此视图运行时,它会将self.selectedValue更新为新值。我需要在弹出此视图时推送此视图的视图中的此值。

如何获取此数据?

1 个答案:

答案 0 :(得分:1)

当我有这个时,我通常有一个'parentReference'数据成员 例如:

#import "A.h";
#import "B.h";

            @implementation A

                - (void) f
                {
                  B *bInstance = [[B alloc] init];
                  bInstance.parentRef = self;

                  [self.navigationController pushViewController: bInstance];
                }

//'B'类声明为

@class A;
@interface B : UIViewController
{
  A *parentRef;
}
@property (nonatomic, assign) A *parentRef;
通过这种方式,你可以回到“召唤”你并做你想做的任何事情的课程

(您可能会认为[self.view superview] == parentRef,但事实并非如此)