Я очень плохо знаком с Objective-C и XCode и надеялся, что кто-нибудь сможет мне немного помочь с основной проблемой программирования.
Я хочу добавить TranslationRegions (пользовательскую модель данных) в стек и вызвать его для использования в контроллере.
Массив должен быть:
- Загружается при запуске приложения
- Доступно для звонка в любое время, в любом месте приложения
В конце концов, элементы массива будут загружены через вызов веб-службы, но сейчас я бы хотел загрузить элементы в моей модели с помощью кода.
Я создал объект (TranslationRegion) с файлами .h и .m, который я хочу использовать для связывания таблицы с.
Я, может быть, и здесь очень сильно ошибаюсь, поэтому любые советы будут оценены.
Регион перевода в настоящее время имеет только одно описание свойстваOfRegion.
Сначала я включил свой контроллер, чтобы показать, что я пытаюсь сделать, а затем мои файлы .h и .m для моей модели.
Фактический контроллер
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Show Regions"])
{
// Need to instantiate the array in here and pass it to the 'setRegions' within the Table View Controller
//[segue.destinationViewController setRegions:regionArray];
}
}
Контроллер табличного представления
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyApp Regions";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the region cell
id region = [self.regions objectAtIndex:indexPath.row];
cell.textLabel.text = [@"" stringByAppendingString:[TranslationRegion descriptionOfRegion:region]];
return cell;
}
TranslationRegion.h
#import <Foundation/Foundation.h>
@interface TranslationRegion : NSObject
@property (nonatomic, readonly) id region;
+ (NSString *)descriptionOfRegion:(id)region;
@end
TranslationRegion.m
#import "TranslationRegion.h"
@interface TranslationRegion()
@property (nonatomic, strong) NSMutableArray *regionStack;
@end
@implementation TranslationRegion
@synthesize regionStack = _regionStack;
- (NSMutableArray *)regionStack
{
if (_regionStack == nil) _regionStack = [[NSMutableArray alloc] init];
return _regionStack;
}
- (id)region
{
return [self.regionStack copy];
}
+ (NSString *)descriptionOfRegion:(id)region
{
return @"This value";
}
@end