我在.h文件中声明了NSString
。然后我在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
打印一些垃圾值。为什么我能解决这个问题?
由于
答案 0 :(得分:0)
您拥有从您负责发布的initWithFormat
返回的对象,但您不拥有从stringWithFormat
返回的返回自动释放字符串的对象,因此不需要释放它(如果你想拥有它,你必须保留它。)
因此,要解决您的问题,请尝试分配您的值,
- (void)viewDidLoad {
arrstrWifiId=[arrWorkflow valueForKey:@"WFID"];
strWifiId=[[NSString alloc] initWithFormat:@"%@",[arrstrWifiId objectAtIndex:0] ];
}