在 objective c 中的表视图控制器中显示 NSMutableArray
showing NSMutabelArray in tableViewController in objective c
我正在将 NSMutableArray 传递给另一个 table 视图,我想在 table 视图中显示它。我的NSMutable数组如下
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;
}
并在 table 视图控制器中接收数据,
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
NSLog(@"%@",self.passingString);
[self.tableView reloadData];
}
我尝试如下显示 mutable 数组,
- (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;
}
但我不明白我在 table 视图上填充数据到底缺少什么。
我认为您没有设置 tableview 委托和数据源。
- (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;
}
我正在将 NSMutableArray 传递给另一个 table 视图,我想在 table 视图中显示它。我的NSMutable数组如下
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;
}
并在 table 视图控制器中接收数据,
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
NSLog(@"%@",self.passingString);
[self.tableView reloadData];
}
我尝试如下显示 mutable 数组,
- (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;
}
但我不明白我在 table 视图上填充数据到底缺少什么。
我认为您没有设置 tableview 委托和数据源。
- (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;
}