我有一个叫TableViewController的SecondViewController。单元格的名称是可以的,一切都很好,但是在加载详细视图(在我的例子中称为ArticleViewController )时,它不希望与详细视图的属性通信。因此,基本上,如果我想在详细的视图中更改一个标签,它就是不能工作。
以下是代码:
SecondViewController.h
@interface SecondViewController : UITableViewController
{
NSMutableArray *json;
}
@endSecondViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ArticleViewController *article = [self.storyboard instantiateViewControllerWithIdentifier:@"ArticleViewController"];
NSDictionary *info = [json objectAtIndex:indexPath.row];
NSLog(@"%@",[info objectForKey:@"username"]);
[article.usernameLabel setText:[info objectForKey:@"username"]];
[self.navigationController pushViewController:article animated:YES];
}ArticleViewController.h
#import <UIKit/UIKit.h>
@interface ArticleViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *articleTitle;
@endArticleViewController.m
-合成性能--
我把标签和ArticleViewController挂上了钩,但是标签没有变。
发布于 2012-01-21 07:02:27
我猜article在执行article.usernameLabel setText:时还没有加载它的nib。所以article.usernameLabel仍然是nil。您可以通过执行article来强制[article view]加载它的nib。但奥德奈里的建议更好。
https://stackoverflow.com/questions/8945868
复制相似问题