开发者

passing a string value to another controller

I am passing a string to another controller

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

CategoriesList *dvController = [[CategoriesList alloc] initWithNibName:@"CategoriesList" bundle:nil];

NSString *category=aBook.name;
dvController.category=category;
[self.navigationCont开发者_高级运维roller pushViewController:dvController animated:YES];
[dvController release];

}

When I get value in dvController it does not show I am setting that to button title

 NSString *title=category;
 [titleButton setTitle:title forState:UIControlStateNormal];


Easiest way is to create a custom init in CategoriesList:

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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜