【发布时间】:2013-12-28 03:53:13
【问题描述】:
嘿,所以我有点卡在这个问题上 - 我环顾四周,找不到任何特定于我的问题的东西,所以请随时重定向我:
我已经设置了一个 MapViewController 导航栏来根据单击的表格单元格来更改标题,但是这个 MapViewController 也可以作为一个选项卡栏项目使用,它会显示一个更大的地图但是当没有点击表格单元格时它不会显示任何标题。
对于 TableViewController.m:
@interface FirstTableViewController () {
NSArray *locations;
}
@end
@implementation FirstTableViewController
- (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;
locations = [NSArray arrayWithObjects:@"Bondi", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (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 [locations count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
//Uncomment to have array auto-name table as oposed to custom designs
//cell.textLabel.text = [locations objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"mapViewer"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
MapViewController *destViewController = segue.destinationViewController;
destViewController.resultsName = [locations objectAtIndex:indexPath.row];
}
}
对于 MapViewController.h 声明的属性:
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) NSString *resultsName;
@property (strong, nonatomic) IBOutlet UINavigationItem *locationName;
@property (strong, nonatomic) IBOutlet UILabel *resultsLabel;
最后是 MapViewController.m:
@interface MapViewController ()
@end
@implementation MapViewController
@synthesize resultsName;
@synthesize resultsLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
resultsLabel.text = [NSString stringWithFormat:@"Showing %@", resultsName];
_locationName.title = resultsName;
}
任何提示/提示将不胜感激 - 谢谢。
【问题讨论】:
标签: ios uitableview uinavigationbar