custom bar ios objective-c ios7 xcode5 interface-builder

ios - bar - Células de tabla estáticas en archivo NIB



custom view navigation bar swift (2)

¿Es posible crear un archivo nib que tenga una vista de tabla con celdas estáticas personalizadas? Quiero crear una vista de tabla similar a un formulario con todo el contenido estático, pero actualmente no estoy usando guiones gráficos. Pude encontrar el menú de tipo de contenido en el guión gráfico predeterminado de mi aplicación, pero estoy usando Nibs, y cuando creo una plumilla UIViewController o una plumilla UITableViewController, en ambos casos no hay menú de tipo de contenido en el inspector de atributos lengüeta.

¿Alguna idea?


Parece que en este momento, lo que estoy tratando de hacer simplemente no es compatible. Archivé un error de Radar en Apple, pero esta es la solución que funcionó para mí.

Solo usa un guión gráfico y llámalo como una punta usando:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"EditProfile" bundle:nil]; EditProfileTVC *vc = [sb instantiateViewControllerWithIdentifier:@"EditProfile"]; vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self.navigationController pushViewController:vc animated:YES];

En su guión gráfico, nombre el controlador de vista en el que desea comenzar como EditProfile, en este caso. Espero que esto ayude a alguien.


Hay un proceso para esto, pero no es demasiado complicado:

  • Cree una nueva clase Cocoatouch presionando Comando + N y seleccionándolo en el menú iOS> Fuente.

  • Asigne un nombre a su clase, conviértala en una subclase de ViewController y finalmente marque la casilla ''Crear también archivos XIB''.

  • Abra su archivo XIB y defina la clase personalizada en el inspector de identidad para señalar el nombre de YourNewViewController

Muestra de esto en el trabajo: en .h:

@interface LocationsListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, weak) myMapManager* mapManager; @property (nonatomic, weak) IBOutlet UITableView* tableView; @property (nonatomic, weak) NSMutableArray* locations; @end

Luego, en .m:

#import "LocationsListViewController.h" #import "CustomCellController.h" #import "myMapAnnotation.h" #import "DetailViewController.h" //Define MKMap details, easier to change later #define kCellHeight 70 #define kMainCellIdentifier @"mainCellIdentifier" #define kMainCellNib @"CustomCell" #define kDetailVCNib @"DetailViewController" @implementation LocationsListViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { //Define initial view titles and such self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = NSLocalizedString(@"MCS Locator", @"MCS Locator"); self.tabBarItem.image = [UIImage imageNamed:@"list"]; self.tabBarItem.title = NSLocalizedString(@"Our Locations", @"Our Locations"); self.mapManager = [myMapManager sharedInstance]; self.locations = self.mapManager.locations; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerNib:[UINib nibWithNibName:kMainCellNib bundle:nil] forCellReuseIdentifier:kMainCellIdentifier]; //Edit button creation, added to bar at top UIBarButtonItem* edit = [[UIBarButtonItem alloc] initWithTitle:@"EDIT" style:UIBarButtonSystemItemEdit target:self action:@selector(editList)]; self.navigationItem.rightBarButtonItem = edit; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.locations count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { myMapAnnotation* currentLocation = [self.locations objectAtIndex:indexPath.row]; CustomCellController *cell = [tableView dequeueReusableCellWithIdentifier:kMainCellIdentifier]; [cell configureCellWithLocation:currentLocation]; return cell; } //Custom methods - (void)editList { if (!self.tableView.editing) { //Editing mode entered [super setEditing:YES animated:YES]; [self.tableView setEditing:YES animated:YES]; [self.navigationItem.rightBarButtonItem setTitle:@"DONE"]; } else { //Done editing [super setEditing:NO animated:YES]; [self.tableView setEditing:NO animated:YES]; [self.navigationItem.rightBarButtonItem setTitle:@"EDIT"]; } } // Edit/delete method - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (UITableViewCellEditingStyleDelete == editingStyle) { [self.locations removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } } //Methods for the singleton and tableview data passing - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return kCellHeight; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { myMapAnnotation* currentLocation = [self.locations objectAtIndex:indexPath.row]; DetailViewController* detailView = [[DetailViewController alloc] initWithNibName:kDetailVCNib bundle:nil]; detailView.location = currentLocation; [self.navigationController pushViewController:detailView animated:YES]; //Push on top } @end

Luego debe hacer lo mismo y crear una "Célula personalizada" (un archivo xib con una vista de 320x65 por ejemplo) junto con una clase como la anterior para definir las celdas.

#import "CustomCellController.h" @implementation CustomCellController - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } - (void)configureCellWithLocation:(myMapAnnotation*)location { self.title.text = location.title; self.subTitle.text = location.subtitle; } @end