开发者

UITableView lazyload - reloadData not working

开发者 https://www.devze.com 2023-03-27 06:04 出处:网络
this seems to be a classic problem but I couldn\'t find any thread with a working solution. I have a UITableView that I want to \"lazyload\" with some XML loaded from my server.

this seems to be a classic problem but I couldn't find any thread with a working solution.

I have a UITableView that I want to "lazyload" with some XML loaded from my server.

My UITableView is correctly declared in the .h...

IBOutlet UITableView *tblView;

...

@property (nonatomic, retain) IBOutlet UITableView *tblView;

...connected in the Interface Builder and synthesized in the .m :

@synthesize tblView;

Now... when the viewcontroller loads, the UITableView delegates (numberOfSectionsInTableView, numberOfRowsInSection) get called once. But I don't have any data at this point so these methods return 0.

Once my data is loaded from the server and parsed, I call...

[tblView reloadData]

... but it doesn't have 开发者_JAVA百科any effect. The delegates are not called at all.

I also tried

[[self tblView] reloadData]

And it doesn't work either.

I even tried to issue the call through the performSelectorOnMainThread like this

...

[self performSelectorOnMainThread:@selector(fillTableWith:) withObject:arrAppointmentsFromServer waitUntilDone:NO];

...

- (void)fillTableWith:(NSMutableArray *)arrAppointmentsFromServer
{
    self.arrAppointments = arrAppointmentsFromServer;

    //Calls a refresh of the tableview
    [tblView reloadData];
}

And this doesn't work either.

Any hints or solution?

Thanks in advance


Ok got it...

my view controller actually inherits from UITableViewController...

Therefore I don't have to declare the IBOutlet, synthesize it or whatever...

When it's time to reload the data, I just do :

[[self tableView] reloadData];

because tableView directly refers to the control itself.

Now the numberOfSectionsInTableView and numberOfRowsInSection methods get called correctly

0

精彩评论

暂无评论...
验证码 换一张
取 消