告诉我,我打算打赌一周,因为单击一个单元格会打开详细视图。
NSArray *MyArray = @[@"hi1",@"hi2",@"hi3"];
我打开故事板,添加一个新视图,使用storyboard segue中的推送(已弃用)适合ID创建链接,但下一步是什么?因为我找不到初学者创建债券的代码。
PS为了以防万一,我完全传播了我的代码
static NSString *cellIdentifier;
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
_startLocation = newLocation;
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error{/* Не удалось получить информацию о местоположении пользователя. */
}
- (void)viewDidLoad
{
[super viewDidLoad];
if ([CLLocationManager locationServicesEnabled]){
self.myLocationManager = [[CLLocationManager alloc] init];
self.myLocationManager.delegate = self;
[self.myLocationManager startUpdatingLocation];
CLLocation *startLocation = self.myLocationManager.location;
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:60.050043 longitude:30.345783];
CLLocation *location3 = [[CLLocation alloc] initWithLatitude:60.040000 longitude:30.323994];
CLLocation *location4 = [[CLLocation alloc] initWithLatitude:60.037389 longitude:30.322094];
float betweenDistance=[startLocation distanceFromLocation:location2];
float betweenDistance3=[startLocation distanceFromLocation:location3];
float betweenDistance4=[startLocation distanceFromLocation:location4];
NSArray *stringsArray2 = @[
[NSString stringWithFormat:@"Distance is %f km",betweenDistance/1000],
[NSString stringWithFormat:@"Distance is %f km",betweenDistance3/1000],
[NSString stringWithFormat:@"Distance is %f km", betweenDistance4/1000]
];
NSString * combinedStuff = [stringsArray2 componentsJoinedByString:@"\n"];
[GMSServices provideAPIKey:@"№№№"];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.93 longitude:30.35 zoom:9];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
//mapView_.settings.myLocationButton = YES;
//mapView_.userInteractionEnabled = YES;
mapView_.frame = CGRectMake(0, 0, 200, 200);
//mapView_.center = self.view.center;
[self.scrollView addSubview:mapView_];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 210)];
self.data = @[
[NSString stringWithFormat:@"Distance is %f km",betweenDistance/1000],
[NSString stringWithFormat:@"Distance is %f km",betweenDistance3/1000],
[NSString stringWithFormat:@"Distance is %f km", betweenDistance4/1000]
];
cellIdentifier = @"rowCell";
[self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
} else {
/* Геолокационные службы не активизированы.
Попробуйте исправить ситуацию: например предложите пользователю
включить геолокационные службы. */
NSLog(@"Location services are not enabled");
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"My title" message:[NSString stringWithFormat:@" %@",[self.data objectAtIndex:indexPath.row],[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 210)]] delegate:self cancelButtonTitle:@"Close window" otherButtonTitles:nil];
[message show];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
答案 0 :(得分:1)
您必须使用segue
将数据传递到该新视图以下是此Passing Data between View Controllers : from uitableview to a details view controller
的答案