UITableViewController Methods are not being called - iphone

As the title says none of my tableview controller methods are being called.
The steps I went through to create my table view are as follows.
1) I created a new file based on UITableViewController and selected the create with xib option. I Named my file myStuffViewController.
2) I have a rootview controller which is a UIViewController. In this view I have a navigation controller that I want to push my tableview controller onto at a certain point.
3) I setup my tableview and nav controller like so
mystuff = [[MyStuffViewController alloc]initWithNibName:#"MyStuffViewController"bundle:[NSBundle mainBundle]];
accountView = [[AccountView alloc] initWithNibName:#"Login" bundle:[NSBundle mainBundle]];
accountViewNavController = [[UINavigationController alloc] init];
accountViewNavController.delegate = self;
NSArray *ar= [NSArray arrayWithObjects:accountView,mystuff, nil];
[accountViewNavController setViewControllers:ar animated:NO];
[accountViewNavController popToRootViewControllerAnimated:NO];
accountView.title=#"Login";
4) Then when a user pushes a button I want to push the table view controller onto the stack like this.
[accountViewNavController pushViewController:mystuff animated:YES];
I've even tried calling [self.tableView reloadData] but none of the methods get called.
Could somebody propose why my table view methods are not being called?
EDIT 1
Just so I'm being as clear as I can be here is what my header file looks like. To be it doesnt seems like I'm missing anything.
#interface MyStuffViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate> {
RemixView *remixView;
NSMutableArray *remixListArray;
TBXML*tbxml;
}
#property(nonatomic,retain)NSMutableArray *remixListArray;
#property(nonatomic,retain)RemixView *remixView;
#property(nonatomic ,retain)TBXML *tbxml;
-(void)fetchRemixList:(NSString *)uid key:(NSString *)k1;
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
#end

Check
You declare in the .h file that you implement the two table view delegates UITableViewDelegate & UITableViewDatasource
In the NIB make sure you link to your delegate in file owner OR if you have created the TableView programmatically make sure you set the delegate ivar also.
Then see if the delegate methods start getting called

Related

UITableView in a UIViewController linked to another ViewController (DetailController)

I have an app on the store that uses a RootViewController linking to a UIViewController (DetailController) and I am working on a new app which basically requires the need for this same feature. But instead, my new app has a UITableView inside a UIViewController linked to a UIViewController. So I thought, i'd copy and paste my RootViewController code into this new UIViewController. So i've linked up the TableView, set delegate and datasource to self and the TableView shows the titles of the items (Hurrah) but when touched, doesn't go to the DetailController? I've used NSLog to determine what part isn't working and of course its the didSelectRowAtIndexPath method… and here is my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *theItem = [items objectAtIndex:indexPath.row];
DetailController *nextController = [[DetailController alloc] initWithItem:theItem];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
The TableViewCell just highlights blue and doesn't link to DetailController.
Thanks in advance!
By "not working" do mean it's not being called, or that it's not pushing the view controller? If the first, then make sure the table view delegate is set correctly. If the second, make sure both nextController and self.navigationController are not nil.

iPhone creating nested views

I'm noob in iPhone programming.
I want to create navigation-based application with several nested views, when first and second are UITableView-type, and the third is simple UIView with my own interface, which I built in Interface builder.
When I run the App, touch the row on the first table-view I transfer to the second, and when I touch the row on the second, I transfer to the third, but on the third View I don't see my interface, which I built in Interface Builder, just blank screen.
This is part of my code, where I try to call my third view:
if(self.reportView == nil){
ReportTypeViewController *viewController =
[[ReportTypeViewController alloc] initWithNibName:#"ReportTypeViewController"
bundle:[NSBundle mainBundle]];
self.reportView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.reportView animated:YES];
self.reportView.title = #"Reports";
That's OK, guys.
I've just didn't add text to my button, that lies on my view, that's why it was blank.
You don't need [NSBundle mainBundle];
it should look like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ReportViewController *vc = [[ReportViewController alloc] initWithNibName:ReportViewController bundle:nil];
vc.title = #"Reports";
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
If you just create the view on demand with the selection it's much easier.
In IB, make sure you remembered to set the Class of File's Owner to ReportTypeViewController, and make sure that the view outlet of File's Owner is connected to your view.
Does ReportTypeViewController really inherit from UIViewController, or is it a UIView, as you say you built in IB?
navigationController pushViewContoller:animated: needs a UIViewController not a UIView. In IB, you can add a UIViewController and move your UIView onto it, or create it programmatically.

Code is exectuting but the view is not loading when called form a function?

I am doing a book kinda application using a viewBased application. The mainView acts as the backgroundView for loading pages. Each page is a different view and have its own nib. When i swipe on a page(actually on the mainView which have loaded the current view/page), that page will be removed and the next/previous page will be added.
[currentPage.view removeFromSuperview];
[self.view insertSubview:nextPage.view atIndex:0];
I have added a popoverController with a barbutton in this mainView. Its intialized with a tableviewController class named popClass. PopClass is another UITableViewController class which will act as the parent for the popViewController.
self.myPopController = [[PopController alloc] initWithStyle:UITableViewStylePlain];
self.myPopOverController = [[UIPopoverController alloc] initWithContentViewController:myPopController];
When I select certain row in the popover, I want the backgroundview(mainView) to load the page corresponding to the number of the row.
For that I have written a function in bookView(mainView) Controller class. And is calling it from the popOver's parent class when i select certain row.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger toPageNumber = indexPath.row + 1;
[viewController changeToPage:toPageNumber];
}
Function and the lines of code are executing but nothing is happening. Even the log lines are printed but no action takes place. The code is the same for removing a page and adding another page which is working successfully when i swipe the view/page.
What is the problem? OR is there anyother way to make the view change in mainView by using the popover?
You need to have refernce of the background view controller in the popover controller.
In the PopController controller you should have a delagate like:
#interface PopController: UITablViewController{
//// other varibales;
id delegate;
}
#property (nonatomic, retain) id delgate;
Now from the class in which you are showing the popovercontroller
you should add this line:
[myPopController setDelegate:self];
Then you can easily acces any method of the main view controller class. By using
[delegate callTheRequiredMethod];
Hope this helps.
Thanks,
Madhup
It's hard to tell what's going wrong without looking at the code. That said, here's what I'd do:
(1) When a row is selected in mainView, present the popoverController modally:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PopoverViewController *vc = [[PopoverViewController alloc] init];
[self.navigationController presentModalViewController:vc animated:YES];
[vc release];
}
(2) When something changes in the popoverController, for example a row is selected, set a value in the parentViewController (which should be the MainView):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.parentViewController.value = someValue;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
(3) Dismiss the popoverController where-ever you choose by calling:
[self dismissModalViewControllerAnimated:YES]`

loading table view on click of button

I have created an iPhone application with using the view based template; the problem is I want to load a table view on the click of button. I have tried this:
initWithNibName:#"xibfile" bundle:[NSBundle mainBundle]...
but table view is not loading, what should I do?
Assuming you are using a navigation controller, in the code related to the action associated to your button, do something like
YourTableViewController *yourTableViewController = [[YourTableViewController alloc] initWithNibName:#"YourTableViewController" bundle:nil];
[self.navigationController pushViewController:yourTableViewController animated:YES];
[yourTableViewController release];
Otherwise, you may present your table view controller as a modal view.
If you're asking how to load a view controller, the pattern looks something like this:
MyViewController* myViewController = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
If you're not using or directly subclassing UITableViewController I'm assuming that your UITableView is an ivar of your UIViewController subclass.
If this is the case you'll need to assign your UIViewController subclass to be the UITableView's delegate and set your UIViewController to conform to the UITableViewDelegate protocol. Also you'll need to create a datasource object that conforms to the UITableViewDataSource protocol. Then set the UITableView's data source to be that UITableViewDataSource object.
So in your header file you'll have:
#class SomeDataSource;
#interface{
UITableView *tableView;
SomeDataSource *dataSource;
}
Then in your implementation block, probably in viewDidLoad, you should include:
tableView.delegate = self;
tableView.dataSource = dataSource;

UITableView with multiple viewcontollers

I just filled my UITableView with Planets. I would like each cell clicked to open into a new Xib (if this sounds like the wrong approach please direct). I can get a secondviewcontroller working, its getting the thirdviewcontroller and fourthviewcontroller working? Thanks.
Place your main view controller (the one with the table) inside a UINavigationController. Then, when the user selects a row, push a new view controller onto it.
The following function will help. As Ben Gottlieb said your main view controller will need to be in a UINavigationController. You need to implement the delegate method for didSelectRowAtIndexPath and this is where you create the new controller for your new view and load it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YourViewController *controller = [[YourViewController alloc] initWithNibName:#"YourViewController"bundle:nil];
[[self navigationController] pushViewController:yourViewController animated:YES];
[yourViewController release]; // don't leak memory
}
Based on the row number you can decide which nib to load.