嗨,我正在嘗試將資料從我的 TableViewController_My_boards 傳遞到 ViewController_Update_Boards,但我不知道該怎么做所以首先我用來自 firestore 的資料創建了一個字典
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
_db = [FIRFirestore firestore];
objNSDictinoaryListOfBoards =[[NSMutableDictionary alloc]initWithCapacity:5];
[[self.db collectionWithPath:@"boards"]
getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot,
NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSString *key = document.documentID;
NSDictionary *boardDetails = document.data;
[self->objNSDictinoaryListOfBoards setObject:boardDetails forKey:key];
//NSLog(@"%@ => %@", document.documentID, document.data);
}
NSLog(@"self->objNSDictionaryListOfBoards= %@", self->objNSDictinoaryListOfBoards);
[self.tableView reloadData];
}
}];}
之后,我在表格視圖單元格中顯示每個專案的名稱
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleIdentifier1" forIndexPath:indexPath];
// Configure the cell...
NSString *boardNo =[objNSDictinoaryListOfBoards allKeys][indexPath.row];
NSString *boardName =objNSDictinoaryListOfBoards [boardNo][@"name"];
cell.textLabel.text=boardName;
return cell;
}
然后當我點擊帶有 didSelectRowIndexPath 的單元格時,我想將資料傳遞給下一個視圖控制器這是我擁有的,但我從這里丟失了。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc=[sb instantiateViewControllerWithIdentifier:@"ViewController_Update_Boards"];
vc.modalTransitionStyle= UIModalTransitionStyleFlipHorizontal;
//[self presentViewController:vc animated:YES completion:NULL];
[self.navigationController pushViewController:vc animated:TRUE];
}
提前致謝
uj5u.com熱心網友回復:
假設 Storyboard 中視圖控制器的自定義類已設定為ViewController_Update_Boards,并且該控制器的頭檔案類似于以下內容:
@interface ViewController_Update_Boards: UIViewController
@property (strong, nonatomic) NSString *boardName;
@end
確保你的TableViewController_My_boards班級在頂部有這個:
#import "ViewController_Update_Boards"
然后將您的didSelectRowAtIndexPath方法更改為:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController_Update_Boards *vc = (ViewController_Update_Boards *)[sb instantiateViewControllerWithIdentifier:@"ViewController_Update_Boards"];
NSString *boardNo =[objNSDictinoaryListOfBoards allKeys][indexPath.row];
vc.boardName = objNSDictinoaryListOfBoards[boardNo][@"name"];
[self.navigationController pushViewController:vc animated:TRUE];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/377302.html
上一篇:嵌套導航切換關閉父級
