2013-08-23 46 views
0

我正在使用Storyboard並有一個viewcontroller從一個我想在目標視圖控制器中預先選擇一個UITableView的單元的轉換。從segue預選一個UITableViewCell

源視圖控制器中的prepareForSeque將字符串值傳遞到目標視圖控制器的NSString中。

我想要做的是加載目標視圖 - 控制,有與這是經SEGUE呼叫傳遞的字符串值相匹配的單元格的UITableView的負載...

問題是 - 的UITableView爲零時我嘗試訪問它在viewDidLoad我的目標視圖控制器...我想撥打電話selectRowAtIndexPath從那裏...

在此先感謝!

回答

0

在準備segue時,您可以引用destinationViewController並對其進行分配或其他調用。

我會在你的viewController.h

建議做一個

@property (nonatomic, strong) NSString *yourCellId; 

然後在準備Segue公司,你可以這麼[[segue destinationViewController] setYourCellId:yourstring],它會設定值。

然後在viewDidLoad中,您可以訪問yourCellId,因爲它會在初始化後,進行設置,viewDidLoad中

0

作出這樣@property(nonatomic,retain) NSString *selectedString;destinationViewController.h的屬性。 在prepareForSegue中,在實例化destinationView後,請致電destinationViewController.selectedString = someSelectedString;。 然後進入賽格。在DestinationViewController.m裏面,做這樣的事情:

-(void)viewDidAppear:(bool)animated 
{ 
    [super viewDidAppear:animated]; 
    //Here you do whatever check you are doing to find out 
    //which row the selected string is in, and put it in 
    NSIndexPath *selectedIndex = //Whatever datasource-way you can figure out 
    [tableView selectRowAtIndexPath:selectedIndex animated:YES scrollPosition:UITableViewScrollPositionNone]; 
} 
相關問題