gpt4 book ai didi

ios - 将选定行的值传递给 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:21:48 24 4
gpt4 key购买 nike

我尝试将所选行的值传递给 View Controller 。在新 View Controller 中记录返回空值。我的错误在哪里?

 2013-06-18 17:28:59.394 App[1790:c07] ID is Here: 35023

2013-06-18 17:28:59.397 App[1790:c07] Value in Next view (null)

2013-06-18 17:28:59.398 App[1790:c07] Label is Here <UILabel: 0x9139810;
frame = (14 140; 255 16); clipsToBounds = YES; opaque = NO;
autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x915ab10>>

表格 View Controller 代码:

NSString *localStringValue;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *value = [myArray objectAtIndex:row];

DetailViewController *second=[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] ;

second.PassID=value;

[self presentModalViewController:second animated:YES];

localStringValue = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
NSLog(@"ID is Here: %@", value);
}

下一个 View Controller 代码:

.h

@interface DetailViewController : UIViewController
{
NSString *PassID;
}
@property (nonatomic, retain) NSString *PassID;
@property (unsafe_unretained, nonatomic) IBOutlet UILabel *label;

.m代码

- (void)viewDidLoad
{

label.text=PassID;
NSLog(@"Label is Here %@",label);

[super viewDidLoad];
}

最佳答案

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *value = [myArray objectAtIndex:row];

DetailViewController *second=[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] ;

/// second.PassID=value; ///Remove the line here


[self presentModalViewController:second animated:YES];

second.PassID=value; ///assign the value after presenting


localStringValue = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
NSLog(@"ID is Here: %@", value);
}

关于ios - 将选定行的值传递给 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17170372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com