I want to make a custom cell for my TableView. But she's presenting problems that I can not solve. It worked normally when I did with the default cell, but when I did custom it gave problem
I was using this explanation to help: link
I made my cell this way ..
SimpleTableCell.xib and SimpleTableCell.h:
SimpleTableCell.m
import"SimpleTableCell.h"
@interface SimpleTableCell ()
@end
@implementation SimpleTableCell
@synthesize nome = _nome;
@synthesize texto = _texto;
@synthesize data = _data;
@synthesize foto = _foto;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
My ViewController (Where is the TableView), this way.
ViewController.m
#import "ViewController.h"
#import "SimpleTableCell.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//________________________
_tabela.dataSource = self;
_tabela.delegate = self;
//________________________
//Na ViewDidLoad eu pego um Json e armazenando seus dados em uma lista (lista manda dados para célula)
_users = [[NSMutableArray alloc] init];
NSURLRequest *requisicao = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.meuSite.com.br/mural/listener.php?a=10"]];
NSData *resposta = [NSURLConnection sendSynchronousRequest:requisicao
returningResponse:nil
error:nil];
NSError *jsonParsingError = nil;
NSArray *array = [NSJSONSerialization JSONObjectWithData: resposta options: nil error: &jsonParsingError];
NSLog(@"result = %@", array.firstObject);
int total = [array count];
for (int x =0; x<total; x++) {
[_users addObject:[array objectAtIndex:x]];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{//tamanho da lista
return [_users count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSLog(@"QUANDO COMPILO SÓ VEM ATÉ AQUI. . .");
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
NSLog(@"%d", 23);
cell = [nib objectAtIndex:0];
NSLog(@"%d", 3);
}
NSDictionary * usuario = [_users objectAtIndex:indexPath.row];
cell.nome.text = [usuario objectForKey:@"nome"];
cell.texto.text = [usuario objectForKey:@"texto"];
cell.data.text = [usuario objectForKey:@"data"];
NSString *img = @"http://diegocavalca.com/wp-content/uploads/2016/01/iphone_6_home_screen_hero.jpg";
NSString *url_imagem = [NSString stringWithFormat:img];
NSLog(@"%@", url_imagem);
NSURL *url=[NSURL URLWithString:url_imagem];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
cell.foto.image =[UIImage imageWithData:data];
}];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property NSMutableArray * users;
@property NSIndexPath * selecionado;
@property (weak, nonatomic) IBOutlet UITableView *tabela;
@end
Error Presented. . .
- [NSNull length]: unrecognized selector sent to instance 0x381cf588 ' If anyone knows how I can resolve this, thank you in advance.