reloadData for a Table View in a View Controller - iphone

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?

Related

Assign own View Classes to Storyboard

See this storyboard containing a Navigation View, Gestures, and a few Views.
Also within is a TabView, which contains an UIImageView and UITableViewController.
To apply my data to this TableView, I need to assign a Controller by using msExampleTableViewController.
The problem: the input/dropdown field removes entry after pressing Enter (like if this class is not assignable).
What is wrong here, and how can it best be done?
NA UITableViewController does assume that the root view will be a UITableView. When you combines UITableView with others controllers.. you can do in your Controller (ViewController in your case):
#interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, assign) IBOutlet UITableView* tableView;
In Interface Builder set both the delegate and dataSource outlets of the table view to be equal to its superview's view controller (File's Owner)...
Now, Your view controller implementation should be the typical TableViewController implementation: cellForRowAtIndexPath, etc.

Converting UIView to UITableView

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:

Reload data of table view subobjec of uiviewcontroller with tableview

i've a class SelezionaProfilo, in this class i've a list of players:
#interface SelezionaProfilo : UIViewController < UITableViewDelegate, UITableViewDataSource > {
UITableView *myTableView;
//my staff
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
all works fine.
i've built a subclass SelectPlayerViewController embeded in navigationcontroller, because i want to have a different reaction to push a row:
#interface SelectPlayerViewController : SelezionaProfilo {
all works fine, i've the players list. And i have the different action.
in the SelectPlayerViewController.m i've added a button on navigation bar, add player button that goes to another class in push navigation.
Now the player was created, but when the view come back to SelectPlayerViewController, i can't see the last player.
in SelezionaProfilo.m:
- (void)viewWillAppear:(BOOL)animated {
[self.myTableView reloadData];
[super viewWillAppear:animated];
}
and in SelectPlayerViewController.m
- (void)viewDidAppear:(BOOL)animated {
[super.myTableView reloadData];
}
i'm sure that enter in this method, but the table doesn't refresh.
I've a tabbar, and i've SelezionaProfilo in another tab, if i select this, i can see the last player, so the SelezionaProfilo class works fine.
can anyone suggets me?
thaks
I resolved it!!!
so if interest to someone....
i've a table view in the xib, i must connect it with File's Owner two Referencing Outlet:
view
myTableView

How to resize a UITableView

In my application, I have a button that pushes a custom view controller (MenuViewController) on click.
#interface MenuViewController : UITableViewController
I wasn't able to resize the tableview. I tried:
self.tableView.frame=CGRectMake(0, 0,100, 100);
self.View.frame=CGRectMake(0, 0,100, 100);
in viewDidLoad and viewWillAppear. Neither of these methods worked.
I have an idea of creating a UIView initwithframe:.. and add MenuViewController as a subview.
Is this the proper way to do it?
MenuViewController is basically a general control that will handle variable init inputs
and will display the cells according to the inputs, the problem is the frame of the table view.
I believe that if you inherit from UIViewController and expose the UITableView as a property and also on the Interface then you can resize it. When you are using UITableViewController then it will always display in full size mode.
UPDATE:
So instead of doing something like this:
#interface TasksViewController : UITableViewController
{
}
You can do something like this:
#interface TasksViewController : UIViewController<UITableViewDelegate>
{
}
#property (nonatomic,weak) IBOutlet UITableView *tableView;
Also make sure that in interface builder you have a UITableView which is hooked to the tableView property in the TasksViewController. Now in your implementation file implement the cellForRowAtIndexPath method and return the cell.

Reload UITableViewController

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];