Reputation: 31
I have a UITableView
embedded inside a UIViewController
but am having a few problems. I've set the delegate of the table view to the view controller.
1) The data source is an array which is being retrieved from the internet. The problem is that when the data is downloaded and placed into the array and [self.tipTableView reloadData]
has been called, it doesn't update the table. I can see that numberOfRowsInSection:
is called and it returns the correct number (not 0) but it doesn't call cellForRowAtIndexPath:
. However, when the array has data in viewDidLoad
, it loads it correctly.
2) I want to make the table hidden by default and then visible when a button is pressed. Setting the table to hidden in viewDidLoad
works fine, but when I try to set it to visible when the button is pressed it doesn't work. I'm trying self.tipTableView.hidden = NO;
for this, which only appears to work in viewDidLoad
and not other methods.
The table view was created in interface builder, it's connected to the view controller as in this image:
Does anyone have any idea why these problems are happening?
Thanks!
Upvotes: 3
Views: 664
Reputation: 13
As far as I know the cellForRowAtIndexPath method is called for the cells which are currently visible on the screen. I guess while you are reloading your table it is still invisible. So maybe you should try to set hidden NO at first and then reload data immediately after that if there is data to show.
Upvotes: 1
Reputation: 2194
It seems to me like you are not connecting your button that initiates the action properly, since you say that it works if you run it from your viewDidLoad method, but does not work when you connect the action to a button.
Are you connecting the button properly in IB?
Are you connecting it as an action or an outlet?
...Or are you just creating the button programmatically?
Upvotes: 0
Reputation: 1422
1:
You have to implement at least the following methods in your datesource:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [yourarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// that's up to you
}
I suppose you forgot to implement numberoOfRowsInSection.
2:
Try:
[self.tableView setHidden:NO];
That should work, provided you are not looping after showing it ( while (condition) do_something; ).
This is the case also if you are downloading something from the network in the main thread.
Upvotes: 0