это мое первое приложение, и в основном эта часть состоит в передаче данных из UItableView во второй View Controll. Мне удалось узнать, как передавать данные из простого NSarray (также в UITable), но моя цель - передать значения из NSDictionary. Все настроено, но я не могу понять, как правильно писать метод PrepareForSegue. Приложение запускается, но ярлык в «DetailView» остается пустым. То, что я получил до сих пор:Objective-c: передача данных из UITable в ViewController с помощью prepareForSegue
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
_citySpots = @{@"Bars" : @[@"Hurricane", @"Black Swan", @"Texas"],
@"Clubs" : @[@"Electric Wizard", @"Offspring", @"The Tunnel"],
@"Restaurants" : @[@"Nando's", @"1/2 Burguer", @"Satellite"],
};
_sectionTitles = [[_citySpots allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
PrepareForSegue Метод:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"spotsDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *destViewController = segue.destinationViewController;
NSString *sectionTitle = [_sectionTitles objectAtIndex:indexPath.section];
NSArray *citySpots = [_citySpots objectForKey:sectionTitle];
destViewController.receiver = [citySpots objectAtIndex:indexPath.row];
}
}
И приемник (заголовок):
#import <UIKit/UIKit.h>
#import "TableViewController.h"
@interface DetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *receiver;
@property (nonatomic, strong) NSString *spot;
@end
Главная:
#import "DetailViewController.h"
@interface DetailViewController()
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
_receiver.text =_spot;
}
Может кто-то помочь мне вне? Благодаря
'destViewController.receiver = [citySpots objectAtIndex: indexPath.row];' => 'destViewController.spot = [citySpots objectAtIndex: indexPath.row];'? – Larme
Нет, это не работает, Larme, ярлык по-прежнему пуст ... – FuManchu
Но в 'viewDidLoad',' _receiver' 'nil'? Значение '_spot' имеет правильное значение? – Larme