gpt4 book ai didi

ios - 在 objective-c 的 tableViewController 中显示 NSMutabelArray

转载 作者:行者123 更新时间:2023-11-29 11:48:59 25 4
gpt4 key购买 nike

我将 NSMutableArray 传递给另一个 TableView ,我想在 TableView 中显示它。我的NSMutableArray如下

2017-02-07 18:32:24.086 krib[13753:2978659] (
"Balcony.png",
"Utilities Included.png",
"Air-conditioning.png",
"Stove.png",
"WiFi Included.png",
"Queen Bed.png",
"Dining Table.png",
"Washing Machine.png",
"Dryer.png",
"Sofa.png",
"TV.png",
"Curtains.png",
"Refrigerator.png",
"Water Heater.png",
"Microwave Oven.png"
)

我将数据发送为,

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"segue"]) {
MZFormSheetPresentationViewControllerSegue *presentationSegue = (id)segue;
presentationSegue.formSheetPresentationController.presentationController.shouldApplyBackgroundBlurEffect = YES;
UINavigationController *navigationController = (id)presentationSegue.formSheetPresentationController.contentViewController;
AmennitiesTableTableViewController *presentedViewController = [navigationController.viewControllers firstObject];
// presentedViewController.textFieldBecomeFirstResponder = YES;

presentedViewController.passingString = facilities;

}

并在 TableView Controller 中接收数据,

- (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];

NSLog(@"%@",self.passingString);
[self.tableView reloadData];

}

我尝试如下显示可变数组,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"facilitiesCell";
AmenitiesTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.facilitylbl.text = [self.passingString objectAtIndex:indexPath.row];

// Configure the cell...

return cell;
}

但我不明白在表格 View 上填充数据到底缺少什么。

最佳答案

我认为您缺少设置 TableView 委托(delegate)和数据源。

- (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
[self.myTable setDelegate:self];
[self.myTable setDataSource:self];

NSLog(@"%@",self.passingString);
[self.tableView reloadData];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.passingString.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"facilitiesCell";
AmenitiesTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if(self.passingString.count > 0){
cell.facilitylbl.text = [self.passingString objectAtIndex:indexPath.row];
}

// Configure the cell...

return cell;
}

关于ios - 在 objective-c 的 tableViewController 中显示 NSMutabelArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42090796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com