Question

I got myself in a problem that I cant find a solution to, so if someone can help me I would appreciate it. I've read a lot of posts on what could be the problem but I did not found any solution. I have a .h

@interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
    UITableView *myTableView;
}
@property (strong, nonatomic)  UITableView *myTableView;
@end

and a .m

@interface FirstViewController ()

@end

@implementation FirstViewController

@synthesize myTableView;
static NSString *CellIdentifier = @"CellIdentifier";

- (void)viewDidLoad
{
    [super viewDidLoad];
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
    myTableView.dataSource = self;
    myTableView.delegate = self;

    [self.view addSubview:myTableView];
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.rowHeight = 325;
    myTableView.backgroundColor = [UIColor yellowColor];
    [myTableView setDelegate:self];

    [myTableView setDataSource:self];
    [myTableView registerClass:[MTTableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self separateByType];

}
-(void)separateByType
{
  NSURL *url = [NSURL URLWithString:tempUrl];
            ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
            [request setDelegate:self];
            [request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *response = [request responseString];
    SBJsonParser *jsonReader = [SBJsonParser new];

    firstJsonData = [NSMutableDictionary dictionary];
    firstJsonData = [jsonReader objectWithString:response error:nil];

    NSLog(@"Calling reloadData on %@", self.myTableView);

    [self.myTableView reloadData];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [[firstJsonData objectForKey:@"data"] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    MTTableViewCell *cell = (MTTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[MTTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    [cell.titleTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
    [cell.descriptionTextlabel setText:[JSONDATA objectAtIndex:[indexPath row]]];
    return cell;

}
Was it helpful?

Solution 2

Don't declare ivar UITableView *myTableView

Don't @synthesize myTableView

Always access myTableView via the property accessor self.myTableView

OTHER TIPS

First Of All , Your code should run well.

  • Be Sure that numberOfRowsInSection function should return valid number.
  • Be Sure that "myTableView" is not nil.

  • Be sure that "myTableView" is seen as background yellow?

-(void)viewWillAppear:(BOOL)animated{

    [self performSelector:@selector(reloadTable) withObject:nil afterDelay:0.2];

    [self.tableView reloadData]; not working 

}

- (void)reloadTable {

    [self.tableView reloadData];
}

above code works for me reload table in selector method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top