0

我有一个带有按钮的 UITableViewController,该按钮触发模态翻转水平 segue 动画到另一个 UITableViewController。在“反面”上,我有一个简单的完成按钮,如果按下它会关闭视图。关闭视图时,我想根据 FlipsideViewController 中“test”字符串的值在 MainTableViewController 中设置“test”字符串。我无法使该连接正常工作。在下面发布我的代码:

MainTableViewController.h

#import <UIKit/UIKit.h>

@interface MainTableViewController : UITableViewController

@property NSString *test;

@end

MainTableViewController.m

#import "MainTableViewController.h"

@interface MainTableViewController ()

@end

@implementation MainTableViewController

@synthesize test;

-(void)viewDidAppear:(BOOL)animated{

    NSLog(@"%@", test);

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10;}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"MainCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;

}

FlipsideTableViewController.h

#import <UIKit/UIKit.h>

#import "MainTableViewController.h"

@interface FlipsideTableViewController : UITableViewController

- (IBAction)done:(id)sender;

@end

FlipsideTableViewController.m

#import "FlipsideTableViewController.h"

@interface FlipsideTableViewController ()

@end

@implementation FlipsideTableViewController

- (IBAction)done:(id)sender{

    NSString *test = @"Hello!";
    // Push the test string to MainTableViewController

    [self dismissViewControllerAnimated:YES completion:nil];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10;}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"FlipsideCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;

}

@end
4

1 回答 1

0

使用委托向后传递数据

请参阅simple-delegate-tutorial-for-ios-development链接。

另请参阅basic-delegate-example链接。

于 2012-10-12T10:52:30.117 回答