我尝试了很多不同的事情,但感觉我错过了一些非常小的东西..
我试图将字符串传递给另一个 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/