0

NSString在 .h 文件中有一个声明。然后我在ViewDidload. 在我的didSelectRowatIndex事件中,想要将该值分配给先前 Viewcontroller 中的另一个字符串。

。H

`

 NSString *strWifiId;

 NSArray *arrstrWifiId;`

`
- (void)viewDidLoad {

        arrstrWifiId=[arrWorkflow valueForKey:@"WFID"];

        strWifiId=[NSString stringWithFormat:@"%@",[arrstrWifiId objectAtIndex:0] ];
 }

`

`

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSArray *array = [self.navigationController viewControllers];

NSLog(@"navi array count ----- %d",[array count]);


UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];




for (UIViewController* viewController in self.navigationController.viewControllers) {


    if ([viewController isKindOfClass:[SendTimeChangeRequestViewController class]] ) {


        SendTimeChangeRequestViewController *groupViewController = (SendTimeChangeRequestViewController*)viewController;


        [groupViewController.btnwrkflwFirstApprove setTitle:selectedCell.textLabel.text forState:UIControlStateNormal];


        groupViewController.pWorkFlowID=strWifiId;

        NSLog(@"WFID---- %@",groupViewController.pWorkFlowID);
        //NSLog(@"CELL TAG----- %@",groupViewController.pAuthEmployeeCode);


        [self.navigationController popToViewController:groupViewController animated:YES];
    }
}

`

这里NSLog打印一些垃圾值。为什么那是 n 我该如何解决?

谢谢

4

1 回答 1

0

您拥有initWithFormat您负责释放的返回对象,但您不拥有stringWithFormat返回自动释放字符串的返回对象,因此不需要释放它(如果您确实想拥有它的所有权,则必须保留它)。

因此,为了解决您的问题,请尝试像这样分配您的价值,

- (void)viewDidLoad {

        arrstrWifiId=[arrWorkflow valueForKey:@"WFID"];

        strWifiId=[[NSString alloc] initWithFormat:@"%@",[arrstrWifiId objectAtIndex:0] ];
 }
于 2013-03-08T15:57:50.520 回答