IOS應用開發02——視圖跳轉

1.代碼控制storyboard中的Segue跳轉

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"pushDetailView"])
    {
        // 點擊cell就會轉向詳細頁面.
        NSArray *sourceArray;
        NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView
                                  indexPathForCell:(UITableViewCell *)sender];
        if (indexPath != nil){
            sourceArray = self.searchResults;
        }
        else{
            indexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender];
            sourceArray = self.records;
        }
        
        // 得到詳細視圖控制器
        TZRecordDetailViewController *destinationController = segue.destinationViewController;
        TZRecord *record = sourceArray[indexPath.row];
        destinationController.title = record.name;
        destinationController.record = record;
        // 設置信息,並傳數據過去
        
    }
}

2.從storyboard中得到一個ViewController方法

 /*  -----------------從storyboard中得到視圖控制器,並且初始化數據,設置信息--------------  */
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    //得到名爲aaa的VC實例 也就是說在storyboard中設置的VC其實是你已鏈接類的一個實例
    TZFriendsViewController *friendsViewController = [storyboard instantiateViewControllerWithIdentifier:@"TZFriendsViewController"];
    friendsViewController.records = recordArray;
    // 定義recordArray數組賦值給friendsViewController
    friendsViewController.title = @"好友";
    friendsViewController.tabBarItem.image = [UIImage imageNamed:@"friends"];
    // 設置標題及圖片
3.navigationcontroller 彈出視圖方法

[self.navigationController popViewControllerAnimated:YES];
// 彈出當前視圖控制器,顯示前一視圖
[self.navigationController popToViewController:viewController animated:YES];
// 彈出到指定視圖控制器
[self.navigationController popToRootViewControllerAnimated:YES];
// 彈出到根視圖控制器

setNavigationBarHidden:BOOL animated:BOOL;
// 設置導航控制器狀態


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章