我試圖將所選行的值傳遞給視圖控制器。日誌在新視圖控制器中返回空值。我的錯誤在哪裏?將選定行的值傳遞給視圖控制器
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>>
TableViewController代碼:
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);
}
下一頁查看控制器代碼:
.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];
}
嘗試打印self.label。 –
讓iVar'label'和屬性'label'在任何地方都會引起混亂。刪除一個或另一個(從您的需要,我會說刪除iVar)。 Xcode會自動爲屬性創建一個iVar,通常爲_(iVar)。 – Putz1103
嘗試通過先改變語句序列,然後賦值 [self presentModalViewController:second animated:YES]; second.label = value; – prasad