【发布时间】:2018-02-04 18:41:53
【问题描述】:
@property NSArray* restaurants;
@end
@implementation RestaurantsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self requestRestaurants];
}
- (void)requestRestaurants {
NSString *urlString = @"https://s3-us-west-2.amazonaws.com/samwell.party/yasminucla/restaurants.json";
NSURL *url = [NSURL URLWithString:urlString];
NSData *restaurantData = [NSData dataWithContentsOfURL:url];
self.restaurants = [NSJSONSerialization JSONObjectWithData:restaurantData
options:NSJSONReadingAllowFragments
error:nil];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.restaurants count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSInteger index = indexPath.row; // Get the row that we're at
NSString* restaurant = self.restaurants[index]; // Get the name of the restaurant for the row from the array
cell.textLabel.text = restaurant; // Set the cell text to be the name of the restaurant
return cell;
}
@end
我在情节提要的 TabViewController 中嵌入了一个 UITableView 控制器,并以编程方式将单元格添加到表格视图中。这些单元格具有从 Internet 的 .json 文件下载的对象。我想在单击时将 mapKit 视图推送到每个单独的单元格,但我不知道该怎么做,因为我无法在情节提要中单独连接单元格。
【问题讨论】:
-
没看清楚。使用委托方法 didselectRowAtIndexPath?
标签: ios objective-c storyboard mapkit segue