Я новичок и поэтому может быть много ошибок в коде. Проблема в том, что. Когда я нажимаю кнопку открытия ячейки detailviewcontroller.but, не показывайте детали, которые я установил в plist. И не показывать ошибок.DetailViewController не отображается подробно
TableViewController.h:
@interface NamesTableViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>
@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;
@end
TableViewController.m:
#import "NamesTableViewController.h"
#import "DetailViewController.h"
@interface NamesTableViewController()
@property (nonatomic, copy) NSDictionary *propertyList;
@property (nonatomic, copy) NSArray *letters;
@property (nonatomic, copy)NSMutableArray *filteredNames;
@property (nonatomic, strong)UISearchController *searchController;
@property (nonatomic, copy)NSMutableArray *arrayPlace;
@end
@implementation NamesTableViewController
@synthesize propertyList, letters, filteredNames, searchController , arrayPlace;
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *tableView = (id)[self.view viewWithTag:1];
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
filteredNames = [[NSMutableArray alloc]init];
searchController = [[UISearchController alloc]init];
self.searchController.searchResultsUpdater = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"];
self.propertyList = [NSDictionary dictionaryWithContentsOfFile:path];
self.letters = [[self.propertyList allKeys] sortedArrayUsingSelector:@selector(compare:)];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView.tag == 1){
return self.letters.count;
}else {
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView.tag == 1) {
NSString *letter = self.letters[section];
NSArray *keyValues = [self.propertyList[letter] allKeys];
[arrayPlace addObject:letter];
return keyValues.count;
} else {
return [filteredNames count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
// Configure the cell...
if (tableView.tag == 1){
NSString *letter = self.letters[indexPath.section];;
NSArray *keyValues = [[self.propertyList[letter] allKeys] sortedArrayUsingSelector:@selector(compare:)];
cell.textLabel.text = keyValues[indexPath.row];
} else{
cell.textLabel.text = filteredNames[indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//[self performSegueWithIdentifier:@"pushDetail" sender:self];
DetailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
// Push the view controller.
[self.navigationController pushViewController:vc animated:YES];
[vc setDictionaryGeter:[arrayPlace objectAtIndex:indexPath.row]];
}
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return self.letters;
}
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (tableView.tag == 1) {
return letters [section];
} else {
return nil;
}
}
#pragma mark Search Display Delegate Methods
-(void)searchDisplayController:(UISearchController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
-(BOOL)searchDisplayController:(UISearchController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[filteredNames removeAllObjects];
if (searchString.length > 0) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [search] %@", self.searchBar.text];
for (NSString *letter in letters) {
NSArray *matches = [[self.propertyList[letter] allKeys]filteredArrayUsingPredicate:predicate];
[filteredNames addObjectsFromArray:matches];
}
}
return YES;
}
@end
DetailViewController.h:
@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *textPlace;
@property (nonatomic) NSString *titleGet;
@property (nonatomic) NSDictionary *dictionaryGeter;
@end
DetailViewController.m:
#import "DetailViewController.h"
@interface DetailViewController()
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
_titleGet = [_dictionaryGeter objectForKey:@"Company"];
_textPlace.text = _titleGet;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
И свойство списка:
<plist version="1.0">
<dict>
<key>A</key>
<dict>
<key>Azer Huseynov</key>
<dict>
<key>Company</key>
<string>test ac</string>
<key>Position</key>
<string>test ap</string>
<key>Email</key>
<string>test ae</string>
<key>Number</key>
<string>test an</string>
<key>Photo</key>
<string>test ai</string>
</dict>
</dict>
<key>B</key>
<dict>
<key>Bahadur Ojakverdiyev</key>
<dict>
<key>Company</key>
<string>test bc</string>
<key>Position</key>
<string>test bp</string>
<key>Email</key>
<string>test be</string>
<key>Number</key>
<string>test bn</string>
<key>Photo</key>
<string>test bi</string>
</dict>
</dict>
</dict>
Помогите мне, ребята!
делает установки 'titleGet' постоянное значение, как "Привет мир", прежде чем толкая ViewController показывает текст" Привет мир" ? Пожалуйста, поместите журнал внутри 'viewDidLoad' внутри 'DetailsViewController' для дальнейшей проверки. –
Я думаю, что эта концепция не нуждается в Plist, вы можете напрямую переместить поля на следующую страницу –
@ Anbu.Karthik, как это сделать? –