我正在将string
传递给另一个控制器
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CategoriesList *dvController = [[CategoriesList alloc] initWithNibName:@"CategoriesList" bundle:nil];
NSString *category=aBook.name;
dvController.category=category;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
当我在dvController
中获得价值时,它没有显示我将其设置为按钮标题
NSString *title=category;
[titleButton setTitle:title forState:UIControlStateNormal];
答案 0 :(得分:2)
最简单的方法是在CategoriesList中创建自定义init:
CategoriesList.h
@interface DetailViewController : UIViewController
{
NSString *category;
}
@property (nonatomic, retain) NSString *category;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil category:(NSString *)categoryName;
CategoriesList.m
@synthesize category;
...
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil category:(NSString *)categoryName;
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.category = categoryName;
}
return self;
}
...
- (void)dealloc
{
[category release];
[super dealloc];
}