2011-08-08 141 views
0

我傳遞一個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

沒有解析,它被稱爲傳遞的ivars值。 – Ishu

+0

並嘗試與self.category。 – Ishu

+0

檢查您是否傳遞任何值?然後檢查是否已經正確聲明瞭'category'(如屬性和綜合),然後再次使用'self.category',同時在同一類(聲明的地方)中使用'category'。如果問題仍然存在,則迴應。 – rptwsthi

回答

2

最簡單方法是在CategoriesList中創建一個自定義init:

類別List.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]; 
} 
相關問題