Boas.
Ando a ler um livro para aprender a programar para iOS, neste momento estou a fazer a segunda aplicação(aplicação de listas) mediante o livro e o Xcode diz que tenho um erro na implementação "CGViewController.m". A app é sobre uma lista de cidades onde o utilizador pode adicionar mais cidades e retirar as que já existem no inicio, e em cada uma ter uma imagem e uma pequena discrição da cidade em si.
O meu código está assim:
#import "CGViewController.h"
#import "CGAppDelegate.h"
#import "City.h"
#import "CityController.h"
@interface CGViewController ()
@end
@implementation CGViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = @"City Guide";
CGAppDelegate *delegate =
(CGAppDelegate *)[[UIApplication sharedApplication] delegate];
cities = delegate.cities;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setEditingBOOL)editing animatedBOOL) animated { //Tenho erro aqui onde tento criar o botão para edição de cada celula(cidade neste caso)
[super setEditing:editing animated:animated];
[tableView setEditing:editing animated:animated]; //Diz que não posso ter tableView
[tableView reloadData]; //não conhece o método reloadData
}
#pragma mark UITableViewDataSource Methods
- (UITableViewCell *)tableViewUITableView *)tv
cellForRowAtIndexPathNSIndexPath *)indexPath {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
if( nil == cell ) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease]; //deu um warning a dizer que é depreciativo a utilização do "initWithFrame"
}
if (indexPath.row < cities.count ) {
City *thisCity = [cities objectAtIndex:indexPath.row];
cell.textLabel.text = thisCity.cityName; }
else {
cell.textLabel.text = @"Add New City...";
cell.textLabel.textColor = [UIColor lightGrayColor];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (NSInteger)tableViewUITableView *)tv numberOfRowsInSectionNSInteger)section {
NSInteger count = cities.count;
if(self.editing){
count = count + 1;
}
return count;
}
#pragma mark UITableViewDelegate Methods
- (void)tableViewUITableView *)tv
didSelectRowAtIndexPathNSIndexPath *)indexPath {
CGAppDelegate *delegate =
(CGAppDelegate *)[[UIApplication sharedApplication] delegate];
CityController *city = [[CityController alloc] initWithIndexPath:indexPath];
[delegate.navController pushViewController:city animated:YES];
[tv deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCellEditingStyle)tableViewUITableView *)tv
editingStyleForRowAtIndexPathNSIndexPath *)indexPath {
if (indexPath.row < cities.count ) {
return UITableViewCellEditingStyleDelete;
}
else {
return UITableViewCellEditingStyleInsert;
}
}
@end
Ando a ler um livro para aprender a programar para iOS, neste momento estou a fazer a segunda aplicação(aplicação de listas) mediante o livro e o Xcode diz que tenho um erro na implementação "CGViewController.m". A app é sobre uma lista de cidades onde o utilizador pode adicionar mais cidades e retirar as que já existem no inicio, e em cada uma ter uma imagem e uma pequena discrição da cidade em si.
O meu código está assim:
#import "CGViewController.h"
#import "CGAppDelegate.h"
#import "City.h"
#import "CityController.h"
@interface CGViewController ()
@end
@implementation CGViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = @"City Guide";
CGAppDelegate *delegate =
(CGAppDelegate *)[[UIApplication sharedApplication] delegate];
cities = delegate.cities;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setEditingBOOL)editing animatedBOOL) animated { //Tenho erro aqui onde tento criar o botão para edição de cada celula(cidade neste caso)
[super setEditing:editing animated:animated];
[tableView setEditing:editing animated:animated]; //Diz que não posso ter tableView
[tableView reloadData]; //não conhece o método reloadData
}
#pragma mark UITableViewDataSource Methods
- (UITableViewCell *)tableViewUITableView *)tv
cellForRowAtIndexPathNSIndexPath *)indexPath {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
if( nil == cell ) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease]; //deu um warning a dizer que é depreciativo a utilização do "initWithFrame"
}
if (indexPath.row < cities.count ) {
City *thisCity = [cities objectAtIndex:indexPath.row];
cell.textLabel.text = thisCity.cityName; }
else {
cell.textLabel.text = @"Add New City...";
cell.textLabel.textColor = [UIColor lightGrayColor];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (NSInteger)tableViewUITableView *)tv numberOfRowsInSectionNSInteger)section {
NSInteger count = cities.count;
if(self.editing){
count = count + 1;
}
return count;
}
#pragma mark UITableViewDelegate Methods
- (void)tableViewUITableView *)tv
didSelectRowAtIndexPathNSIndexPath *)indexPath {
CGAppDelegate *delegate =
(CGAppDelegate *)[[UIApplication sharedApplication] delegate];
CityController *city = [[CityController alloc] initWithIndexPath:indexPath];
[delegate.navController pushViewController:city animated:YES];
[tv deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCellEditingStyle)tableViewUITableView *)tv
editingStyleForRowAtIndexPathNSIndexPath *)indexPath {
if (indexPath.row < cities.count ) {
return UITableViewCellEditingStyleDelete;
}
else {
return UITableViewCellEditingStyleInsert;
}
}
@end