iphone - 如何将字符串从一个 uiviewcontroller 传递到另一个

标签 iphone ios uitableview

我尝试了很多不同的事情,但感觉我错过了一些非常小的东西..

我试图将字符串传递给另一个 View Controller ,但是当我 NSLog 时,我得到返回 (null)...

这就是它的样子,我已经尝试了很多例子,我几乎准备放弃..

//secondview.h
@interface SearchResultsViewController : UITableViewController {

    NSString *setRequestString;

}

@property (nonatomic, retain) IBOutlet NSString *setRequestString;

//secondview.m
//...
@synthesize setRequestString;
//...
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%@", setRequestString);
}


//firstview.m
//...
#import "secondview.h"
//...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    //--- Idendify selected indexPath (section/row)
    if (indexPath.section == 0) {
        //--- Get the subview ready for use
        secondview *sec = [[secondview alloc] initWithNibName:@"secondview" bundle:nil];
//...
        switch (indexPath.row)
        {
                case 0: sec.title = @"Manufacture";
                sec.setRequestString = [NSString stringWithString:@"yo"];
                break;
//...

等等..

最佳答案

在要向其发送数据的类中声明一个方法,并从另一个类调用该方法,并将数据作为该方法的参数传递。如果你想保持简单,你可以尝试使用 NSUserDefaults。希望这可以帮助。快乐编码......:)

关于iphone - 如何将字符串从一个 uiviewcontroller 传递到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7302320/

相关文章:

iphone - Storyboard中自定义单元格中的 UIActivity 指示器

ios - 该证书由未知机构签署

ios - 在 tableView 中插入两个数组 - 连接时出错

iphone - 我应该在哪里执行可达性检查?

Iphone UITableView 自定义单元格按钮事件

iphone - 如何在 iphone 中检查单元格是否有 subview ?

ios - 单击下拉菜单时如何调整 tableView 的高度?

ios - iPhone相机无法设置长时间曝光

ios - AudioUnit 录音每 30 秒出现一次故障

ios - UITableViewCell willDisplayCell 方法难题