Jump to content
Sign in to follow this  
Moneybag

[Resolvido] Ajuda - Xcode App Iphone

Recommended Posts

Moneybag

Boas pessoal

Estou a seguir um tutorial na net sobre uma aplicacao onde e possivel inserir dados e ver os mesmos dados duma tabela em mysql. Mas tou a ter um problema na aplicacao pois consigo inserir os dados mas depois nao os consigo ver na tableview.

Alguem que perceba de xcode me poderia ajudar, eu posso compactar o projecto e mandar um link para download do projecto para que possam indetificar o problemas .

Ja revi o tutorial umas 10 vezes e tenho tudo exatamente igual . A app tem 2 tab , uma view para inserir e outra tableview para ler os dados que estao guardados numa base de dados e na qual o programa recebe os dados por json.

Agradecia muito a quem me podesse ajudar ;)

Share this post


Link to post
Share on other sites
Moneybag

#import "Atendimentos.h"
@interface Atendimentos ()
@end
@implementation Atendimentos
- (id)initWithStyle:(UITableViewStyle)style
{
   self = [super initWithStyle:style];
   if (self) {
    // Custom initialization
   }
   return self;
}
- (void)viewDidLoad
{
   [super viewDidLoad];
   [self getData];
   // Uncomment the following line to preserve selection between presentations.
   // self.clearsSelectionOnViewWillAppear = NO;

   // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
   // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void) viewWillAppear:(BOOL)animated{
   [self getData];
   [self.tableView reloadData];
}
-(void) getData{
   NSMutableString *strUrl = [[NSMutableString alloc] initWithFormat:@"http://xcode5.comze.com/buscaAtendimento.php?"];

   NSURL *url = [NSURL URLWithString:strUrl];

   NSData * data = [NSData dataWithContentsOfURL:url];

   NSError *erro;

   listaAtendimentos = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&erro];


}

- (void)didReceiveMemoryWarning
{
   [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
   // Return the number of sections.
   return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
   // Return the number of rows in the section.
   return [listaAtendimentos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

   // Configure the cell...

   if (cell == nil) {

    cell = [[uITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
   }

   NSDictionary *atendimento = [listaAtendimentos objectAtIndex:indexPath.row];
   cell.textLabel.text = [atendimento objectForKey:@"nomeCt"];
   cell.detailTextLabel.text = [atendimento objectForKey:@"id"];


   return cell;
}

deixo aqui o codigo da class que controla a tableview se alguem vir algo de errado diga me sff

Share this post


Link to post
Share on other sites
KTachyon

Aquilo que o teu URL retorna:

[{"id":"5","nomeFunc":"edison","nomeCt":"paulo","telefone":"25345","problema":"problema x","solucao":"solucao yr"},{"id":"3","nomeFunc":"912521827","nomeCt":"Mafalda Caldas","telefone":"912521827","problema":"Problema no router","solucao":"Subtituicao do router"},{"id":"4","nomeFunc":"Ze","nomeCt":"Ascensao","telefone":"912521827","problema":"Problema no cabo","solucao":"Substituicao do cabo"}]
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

Aquilo que a variável erro tem:

Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it isn’t in the correct format." (Garbage at end.) UserInfo=0x1005025c0 {NSDebugDescription=Garbage at end.}

Edited by KTachyon

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Moneybag

este erro nao sera porque as linhas da tabela que o url retoma nao estao separadas por um enter (break line)? Como poderei resolver este erro? Aqui fica o codigo php para se poderes detectar se existe algum erro:

mysql_connect($mysql_host,$mysql_user,$mysql_password) or die ("Erro de Conexao");
mysql_select_db($mysql_database) or die ("Erro ao Selecionar Base de Dados");
$querty = "SELECT * FROM tbl_atendimento";
$result = mysql_query($querty) or die ("Erro ao selecionar tabela");
mysql_close();

$linhas = array();
while($r = mysql_fetch_assoc($result)){
$linhas[] = $r;
}
echo json_encode($linhas);

Ja agora no xcode como posso ver o erro que a variavel erro gera?

Share this post


Link to post
Share on other sites
KTachyon

Não, o problema é o JSON levar com o Javascript das analytics do Hosting24. O parser de JSON não consegue ler isso e dá erro.

Tens que conseguir tirar isso de lá ou fazer um tratamento ao dados antes de os passares para o parser.

Na variável erro tens lá a informação sobre o erro que ocorreu. Podes mandar imprimir com:

NSLog(@"%@", erro);

Edited by KTachyon

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Moneybag

Ja desabilitei o javascript que o host incorporava nas paginas e o programa ja esta a funcionar , Obrigado KTachyon :thumbsup:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.