2012-08-25 56 views
0

我有一個標籤的情況!我做了一個tableView,它在解析時與一個數據表相關聯。當我選擇行視圖控制器傳遞到視圖,但值是!我所有的NSLog都指定了數據通過的事實!但我無法在viewController的標籤上顯示該圖標!請幫助..我錯過了什麼?所有的連接都沒有與文件的所有者。這些都是我的文件..無法顯示UILabel -xcode

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


    PFObject *object = [self.objects objectAtIndex:indexPath.row]; 

    NSInteger row = [indexPath row]; 
NSLog(@"%i",row); 

MyTableViewDetail * MTD = [[MyTableViewDetail alloc] initWithNibName:@"MyTableViewDetail" bundle:nil]; 

NSLog(@"text=%@",[object objectForKey:@"columntext"]); 
MTD.label1 = [object objectForKey:@"columntext"]; 
NSLog(@"label1= %@",MTD.label1); 

[self.navigationController pushViewController:MTD animated:YES]; 
//tableView.backgroundColor =[UIColor clearColor]; 


} 

所有我的NSLog的都指向正確的方向。但由於某些原因,LABEL1不顯示值。這裏是我的其他文件..

#import "MyTableViewDetail.h" 
#import "MyTableController.h" 

@interface MyTableViewDetail() 

@end 

@implementation MyTableViewDetail 
@synthesize label1; 
@synthesize imagedetail; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 


    // Custom initialization 
} 
return self; 
} 


- (void)viewDidLoad{ 
[super viewDidLoad]; 
} 


- (void)viewDidUnload 
{ 
[self setLabel1:nil]; 
[self setImagedetail:nil]; 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

和我的.h:

#import <UIKit/UIKit.h> 
#import <Parse/Parse.h> 
#import "MyTableController.h" 

@interface MyTableViewDetail : UIViewController{ 

} 

@property (strong, nonatomic) IBOutlet UILabel *label1; 
@property (strong, nonatomic) IBOutlet UIImageView *imagedetail; 

@end 

回答

2

應設置標籤的文本與MTD.label1.text = ...代替的MTD.label1 = ...

UPDATE:

在您的評論的NSLog()輸出可以看到MTD.label1nil開始。 原因是標籤僅在新視圖實際加載後才連接。解決的辦法是創建一個單獨的屬性,例如「columntext」 在MyTableViewDetail,然後

  • 設置MTD.columntext = [object objectForKey:@"columntext"];
  • MyTableViewDetailviewDidLoad設置self.label1.text = self.columntext;
+0

試過也..它不工作..當我運行MTD.label1 = ... NSLog(@「label1 =%@」,MTD.label1);顯示我想要的結果。當我運行MTD.kabel1.text = ... NSLog顯示「null」。所以我真的不知道我在這一點上錯過了什麼。 – snksnk

+0

你可以顯示實際的NSLog()輸出嗎? –

+0

這些是NSLogs與MTD.label1.text = .. 2012-08-26 15:15:08.790 pyxida3 [7427:c07] 0 2012-08-26 15:15:08.790 pyxida3 [7427:c07] text = test3 2012-08-26 15:15:08.790 pyxida3 [7427:c07] label1 =(null) and these this with MTD.label1 = ... 2012-08-26 15:16:57.457 pyxida3 [7470:c07] 0 2012-08-26 15:16:57.457 pyxida3 [7470:c07] text = test3 2012-08-26 15:16:57.457 pyxida3 [7470:c07] label1 = test3 – snksnk