2013-05-07 28 views
0
传递价值

在我的第二个控制器,当用户选择一行并点击返回按钮IOS:从UITableView中排在的UILabel第一个控制器

后,我想更新一个UILabel与文本的选择。

我在第一个控制器上添加了一个UILabel并连接到h。文件但我不知道如何继续

I would like to replicate the GENERAL/AUTO-LOCK function in iPhone/iPad Settings. 

回答

0

您应该为此使用委托。

SecondViewController.h:

@protocol SecondViewControllerDelegate; 

@interface 
... 
@property (nonatomic, assign) id <SecondViewControllerDelegate> delegate; 
... 
@end 

@protocol SecondViewControllerDelegate <NSObject> 
- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text; 
@end 

SecondViewController.m:

@implementation 
... 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [self.delegate secondViewController:self didTapRowWithText:cell.yourLabel.text]; 
} 
... 
@end 

谁创造和推动SecondViewController(也许/希望也一日一):

// put this after secondViewController initialization 
secondViewController.delegate = self; 

- (void)secondViewController:(SecondViewController *)vc didTapRowWithText:(NSString *)text 
{ 
    firstViewController.yourLabel.text = text; 
} 
+0

在最后一部分FirstController我有一些怀疑.....我必须实现PrepareForSegue ...现在我在storyboard中使用连接 – 2013-05-07 17:13:06

+0

不知道你正在使用故事板..但通常你可以为控制器设置一个故事板ID,并通过代码中的这个ID访问控制器,据我所知。 – d4Rk 2013-05-08 09:54:46

+0

谢谢。之后,在故事板上放置一个ID作为分区,所有工作都很好 – 2013-05-09 07:39:46

相关问题