I'm trying to reload data in a UITableViewController after a location is found. This also means after the viewDidLoad method. My class is extending a UITableViewController with this interface:
#interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate>
in the implementation I try to reload data using
[self.view reloadData];
reloadData doesn't seem to be a method of UITableViewController or the view because I get an error:
Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments
Can someone please post some code of how to reload a table view extended like in my case?
you have to do it on the UITableView over [self.tableView reloadData];
Related
I've done this before but I have no idea what I'm missing.
I started the project as a single View project.
Then converted the ViewController to inherit from UITableViewController like so:
#interface ViewController : UITableViewController
went into the .xib for this ViewController and changed the class in the Custom Class section form UIView to UITableView:
Looking in my other project(s) where the ViewControllers are just straight TableView controllers, I don't see what else needs to be done, but when I run the app or when I view the xib it's not showing a tableview.
You'll need to drag out a UITableView in Interface Builder to replace the UIView. Then add the UITableViewDataSource and UITableViewDelegate protocols to your view controllers header file and connect the datasource and delegate outlets from your UITableView to your view controller in Interface Builder.
#interface ViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
add delegate & dataSource. i think you are forgotten to add delegates &dataSource thats why its not showing table. add following lines to your viewDidLoad().
self.myTableView.dataSource = self;
self.myTableView.delegate = self;
after this also implements the required methods of delegate, that are
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return
10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//your code for cell data
}
What init method are you using in the .m file. You need to use the
[[UITableViewController alloc] initWithStyle:UITableViewStylePlain]
allocation method and make sure you have included the<UITableViewDataSource, UITableViewDelegate> and the relevant datasource and delegate methods.
Ok,
basically, if you want to just have a UITableViewController from scratch without having to manually do the above, just create a new Obj-C class, have it inherit from UITableViewController, and select to create a xib, and it will give you a viewcontroller and view already wired to working with a UITableView:
The UITableview reloadData function is not calling the cellforRowAtIndexPath method. Following things I had tried:
Call [self.myTableView reloadData];
call reloadData method on ViewWillAppear too.
written self.myTableView.delegate=self; and self.myTableView.datasource=self too.
Also I have test using NSLog that number of rows are updating properly.
Data source and delegate are connected in storyboard.
I guess you haven't declared delegate in your .h file.
Example.
#interface ClassName:UIViewController <UITableViewDelegate>
Does your view conform to UITableViewDelegate and UITableViewDatasource?
And does it at least implement all of the required methods in those protocols? also, there's no need to say self.myTableView, you could just say myTableView if you're working inside of the class.
And it sounds silly, but did you forget to save your storyboard? I've done that on more than one occasion.
Did you implement the method?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //Return the number of sections you want
}
It's easy to forget, since by default it returns 0.
If you don't do it the tableview thinks it has no sections and does not ask for any row.
Make sure you set the table view's delegate:
tableView.delegate = _an_object_that_conforms_to_UITableViewDelegate_;
This is normally the view controller in which you've declared the table view so you would have:
tableView.delegate = self;
Just make sure the view controller that contains the table view and acts as it's delegate declares itself as an UITableViewDelegate:
#class MyViewController <UITableViewDelegate> {
UITableView *tableView;
...
Tried programming more in an OO manner.
NOTE:
Seems the problem is related to having a UITableView(which is a type of scrollview) ontop of another UIScrollView. Trying to get clarification on how to make this work.
So i made a UITableViewController subclass and add that as an object in my Mainview class.
#interface NRTableVC : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray * tableLabelsArray;
}
#end
The table scrolls and displays OK.
But my
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Did select row");
}
method never gets called.
in my Mainview class I use it as follows
RTable = [[[NRTableVC alloc] initWithStyle:UITableViewStylePlain]autorelease];
[scrollview addSubview:RTable.view];
I was wondering so I need to somehow set self as the delegate or something like that.
Anybody able to give me some hints as to what is wrong?
Many Thanks,
Code
Have you set delegate for tableview? Without delegate set it won't call any delegate methods.
What I usually do is, in the View I want the tableview is create an instance
I do this in ViewDidLoad or the LoadView methods
UITableView *tableView = [UITableView alloc] init...
tableView.delegate = self;
tableView.datasource = self;
Then I add it as a subview of the current view.
This means your MainView needs to implement the tableView datasource and delegate methods.
Edit:
If you use interface builder, remember to drag the datasource and delegates to the fileowner
Is anything retaining RTable? You're autoreleasing it but you don't show any code that indicates it's being retained anywhere.
I have a UITableView inside a UIViewController like so:
.h
#interface OutageListViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> {
IBOutlet UITableView *outageTable;
.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Selected");
}
I have customized table cell:
//EDIT
I have fire UILabel side by side on my customized view, as well as a background spreading the entire area. But after resizing/removing the background image and label I putted on the customized cell, "didSelectRowAtIndexPath" is still not being called.
//END EDIT
#interface AbstractSummaryListViewCell : UITableViewCell {...}
and
#interface FiveColumnSummaryCell : AbstractSummaryListViewCell {...}
This UIView is inside another UIView:
#interface CustomTabBarController : UIViewController {
OutageListViewController *outageListViewController;
And my AppDelegate add this to the window:
[window addSubview:[customTabBarController view]];
Now I'm trying to determine which cell get clicked and didSelectRowAtIndexPath doesn't get called, I have dataSource and delegate connect from the UITableView to File's Owner, in fact the data populates correctly as my "cellForRowAtIndexPath" specifies, any ideas how can I fix this?
Thanks!
I solved it: forgot to check User Interaction Enabled in my customized cell xib. What a fool!
Are the following properties of UITableView all YES?
allowsSelection
allowsSelectionDuringEditing
Edit:
I think Paul is right. The delegate property has some problem. You can check the delegate property of tableView inside -(void)viewDidLoad. As you said, they should be connected to FileOwner in xib. So the following codes won't obtain nil.
- (void)viewDidLoad {
[super viewDidLoad];
// They should not be nil.
NSLog(#"delegate:%# dataSource:%#", self.tableView.delegate, self.tableView.dataSource);
}
It's possible that the view controller has not been connected to the delegate property of the outageTable anywhere.
You can make a quick test... Remove the "big" label and see if the didSelectRowAtIndexPath is called.
Hello I have a view controller that loads from an xib i created. It has two toolbars and a table view in that.
I add this too the header file in the ViewController
#interface FilterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
When I do
[self.tableView reloadData]
It does throws up an error and does not build.
Just making your UIViewController conform to UITableViewDataSource and UITableViewDelegate does not automatically give you a tableView reference.
You need to create a tableView IBOutlet and connect it in Interface Builder.
Also, why not just inherit UITableViewController instead of a UIViewController?